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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions generate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
3 changes: 2 additions & 1 deletion generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!)

strings.Join(config.Operations, ", "))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
no queries found, looked in: testdata/errors/NoQuery.go
no queries found, looked in: testdata/errors/NoQuery.go (configure this in genqlient.yaml)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
no queries found, looked in: testdata/errors/NoQuery.graphql
no queries found, looked in: testdata/errors/NoQuery.graphql (configure this in genqlient.yaml)