-
Notifications
You must be signed in to change notification settings - Fork 114
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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) | ||||||
} | ||||||
_, err = io.Copy(w, r) | ||||||
return err | ||||||
return errorf(nil, "unable to write default genqlient.yaml: %v", err) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Since our |
||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Operations are slices of strings, so changing to There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, ", ")) | ||
} | ||
|
||
|
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) |
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.
Since our
errorf
does its own wrapping, we don't need to usew
, but thefmt.Sprintf
inerrorf
might benefit from+v
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.
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.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.
(Do you mean
%#v
? I don't think we want the quotes here, although below they might be helpful.)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 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.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.
Ah, thanks! We actually do
err.Error()
before passing it intoSprintf
, so%+v
isn't necessary. (And in general I'd like to aim for more human-readable error messages than even%+v
would give.)