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

Add clearer error text a few places #117

Merged
merged 2 commits into from
Sep 28, 2021
Merged

Add clearer error text a few places #117

merged 2 commits into from
Sep 28, 2021

Conversation

benjaminjkraft
Copy link
Collaborator

Summary:

It's nice to be clear here because it may be your first interaction with
genqlient!

Test plan:

make check

It's nice to be clear here because it may be your first interaction with
genqlient!

Test plan:
make check

Reviewers: steve,marksandstrom
@@ -117,8 +117,8 @@ func initConfig(filename string) error {
}
w, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o644)
if err != nil {
return err
return errorf(nil, "unable to write default genqlient.yaml: %v", err)
Copy link
Member

@StevenACoffman StevenACoffman Sep 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return errorf(nil, "unable to write default genqlient.yaml: %v", err)
return errorf(nil, "unable to write default genqlient.yaml: %+v", err)

Since our errorf does its own wrapping, we don't need to use w, but the fmt.Sprintf in errorf might benefit from +v

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would + do here? It seems to me it would only help for ints and %+q, but I may not have read the documentation carefully enough.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Do you mean %#v? I don't think we want the quotes here, although below they might be helpful.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the value is a struct, the %+v variant will include the struct’s field names.
The %#v variant prints a Go syntax representation of the value, i.e. the source code snippet that would produce that value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks! We actually do err.Error() before passing it into Sprintf, so %+v isn't necessary. (And in general I'd like to aim for more human-readable error messages than even %+v would give.)

}
_, err = io.Copy(w, r)
return err
return errorf(nil, "unable to write default genqlient.yaml: %v", err)
Copy link
Member

@StevenACoffman StevenACoffman Sep 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return errorf(nil, "unable to write default genqlient.yaml: %v", err)
return errorf(nil, "unable to write default genqlient.yaml: %+v", err)

Since our errorf does its own wrapping, we don't need to use w, but the fmt.Sprintf in errorf might benefit from +v

Copy link
Member

@StevenACoffman StevenACoffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two potential nits, unlikely to be a real issue.

@@ -316,7 +316,8 @@ func Generate(config *Config) (map[string][]byte, error) {
// way. (As-is, we generate a broken file, with just (unused) imports.)
if len(document.Operations) == 0 {
// Hard to have a position when there are no operations :(
return nil, errorf(nil, "no queries found, looked in: %v",
return nil, errorf(nil,
"no queries found, looked in: %v (configure this in genqlient.yaml)",
Copy link
Member

@StevenACoffman StevenACoffman Sep 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Operations are slices of strings, so changing to %+v is useless at present, but if we ever pivot to making them structs, we adding the harmless + would make it Just Work™️

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I see why we would make this a struct(s)? Or rather, if we did, we would want to change the error to still just print the filenames. (The snapshot-test will help us remember!)

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.

2 participants