Skip to content
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

Merged
merged 13 commits into from
Jul 25, 2018
Merged

Create orb #32

merged 13 commits into from
Jul 25, 2018

Conversation

zzak
Copy link
Contributor

@zzak zzak commented Jul 25, 2018

I had accidentally merged #28 before #31 so going full circle here... :)

@codecov-io
Copy link

codecov-io commented Jul 25, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@41b2030). Click here to learn what that means.
The diff coverage is 17.3%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master      #32   +/-   ##
=========================================
  Coverage          ?   40.07%           
=========================================
  Files             ?       11           
  Lines             ?      776           
  Branches          ?        0           
=========================================
  Hits              ?      311           
  Misses            ?      442           
  Partials          ?       23
Impacted Files Coverage Δ
cmd/diagnostic.go 27.27% <ø> (ø)
cmd/build.go 34.32% <0%> (ø)
cmd/orb.go 26.95% <17.64%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 41b2030...08bddb8. Read the comment docs.

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, ": "))
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

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
Copy link
Contributor

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)
}
Copy link
Contributor

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 of response.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.

@@ -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")
Copy link
Contributor

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
Copy link
Contributor

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))
Copy link
Contributor

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.

@hannahhenderson
Copy link
Contributor

hannahhenderson commented Jul 25, 2018

@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.

@hannahhenderson hannahhenderson changed the title Create namespace Create orb Jul 25, 2018
Zachary Scott added 7 commits July 26, 2018 06:59
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
@zzak zzak dismissed marcomorain’s stale review July 25, 2018 23:18

All of Marc's comments were addressed and this PR should be ready to go after pairing with John.

@zzak zzak merged commit 0357eb2 into master Jul 25, 2018
@zzak zzak deleted the create-namespace branch July 25, 2018 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants