-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create orb #32
Create orb #32
Conversation
Co-authored-by: Hannah Henderson <[email protected]>
Co-authored-by: <[email protected]>
[CIRCLE-12217] Create orb from CLI
Codecov Report
@@ Coverage Diff @@
## master #32 +/- ##
=========================================
Coverage ? 40.07%
=========================================
Files ? 11
Lines ? 776
Branches ? 0
=========================================
Hits ? 311
Misses ? 442
Partials ? 23
Continue to review full report at Codecov.
|
api/api.go
Outdated
@@ -63,7 +74,7 @@ func (response GQLResponseErrors) ToError() error { | |||
messages = append(messages, response.Errors[i].Message) | |||
} | |||
|
|||
return errors.New(strings.Join(messages, ": ")) | |||
return fmt.Errorf(strings.Join(messages, ": ")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the change from the errors
package to string-formatting (fmt
) package here? IMO using the errors package is more clear of the intent, and more clear still since there is no string-formatting going on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be due to the nature of how these 2 PRs were merged, sorry about that.
I will fix it and address the other comments tomorrow unless @johnswanson or @hannahhenderson get to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The linter actually screamed at me for errors.New
and demanded fmt.Errorf
. I assumed that was because the error, in this case, is only a formatted string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hannahhenderson If linter warnings failing builds becomes a nuisance, I think we can check for them in bash and choose to not fail the build:
https://github.com/alecthomas/gometalinter#exit-status
api/api.go
Outdated
@@ -243,7 +254,7 @@ func getOrganization(ctx context.Context, logger *logger.Logger, organizationNam | |||
err := graphQLclient.Run(ctx, request, &response) | |||
|
|||
if err != nil || response.Organization.ID == "" { | |||
err = errors.Wrap(err, fmt.Sprintf("Unable to find organization %s of vcs-type %s", organizationName, organizationVcs)) | |||
err = fmt.Errorf("Unable to find organization %s of vcs-type %s", organizationName, organizationVcs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is destructive - the original error is lost. Let's suppose that error is a network failure, we want the error message to include this information, so that the user can take action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. This will need to become an if-else statement, then.
From what @johnswanson and I could tell, when the error is nil
(like when the response is empty), if you wrap it with a string the end result is still nil
(so the subsequent err != nil
checks don't behave as-desired).
Do you know if there's a better way to handle this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcomorain @hannahhenderson The change isn't destructive. These two lines have equivalent return values. fmt.Errorf
returns an error
object with string interpolation:
https://golang.org/pkg/fmt/#Errorf
See also: https://www.reddit.com/r/golang/comments/6ffrie/fmterrorf_or_errorsnew/
api/api.go
Outdated
// creating an orb | ||
type CreateOrbResponse struct { | ||
Orb struct { | ||
CreatedAt string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createdAt
doesn't seem to be used anywhere. Let's remove from the GQL query and the response struct.
api/api.go
Outdated
|
||
if err != nil || response.RegistryNamespace.ID == "" { | ||
err = fmt.Errorf("Unable to find namespace %s", name) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of comments here:
- Let's split the case of when
err
is nil from the checking ofresponse.RegistryNamespace.ID
. We want to either return the error, or a wrapper around the error when it is not null. - When can
response.RegistryNamespace.ID
be empty/null? That seems like a fundamental failure in the API schema.
cmd/diagnostic.go
Outdated
@@ -25,7 +25,7 @@ func diagnostic(cmd *cobra.Command, args []string) error { | |||
Logger.Infof("GraphQL API endpoint: %s\n", endpoint) | |||
|
|||
if token == "token" || token == "" { | |||
return errors.New("please set a token") | |||
return fmt.Errorf("please set a token") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use a formatting function here for a static string?
api/api.go
Outdated
return nil, err | ||
} | ||
|
||
return orb, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you return createOrbWithNsID(ctx, logger, name, namespaceID)
then you can delete the next 5 lines of code.
api/api.go
Outdated
err := graphQLclient.Run(ctx, request, &response) | ||
|
||
if err != nil { | ||
err = errors.Wrap(err, fmt.Sprintf("Unable to create orb %s for namespaceID %s", name, namespaceID)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In looking into the difference between fmt.Errorf
and errors.New
I learned that errors.Wrapf
exists. That will neaten a bunch of code up.
@zzak #28 should have come before #31. This is the work for creating an orb, although it has a few string-updates for creating a namespace. Update: Ohhhhhhhhhhh. I had #31 against #28 so you didn't have to look at as big a diff. Once #28 was merged, the base-branch for #31 could be changed to Master. |
Please run `make dev` to get the latest version or `make lint` won't work for you.
We should come back to this and make sure addOrbElementsToBuffer error is handled properly.
WRT: error handling and unused createdAt in responses
Until this docker image is updated: https://github.com/supinf/dockerized-tools/tree/master/golang/gometalinter
All of Marc's comments were addressed and this PR should be ready to go after pairing with John.
I had accidentally merged #28 before #31 so going full circle here... :)