-
Notifications
You must be signed in to change notification settings - Fork 843
Use github.com/pkg/errors and store cause of errors in FormattedError #279
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
Conversation
+1 Certainly in need of this one. Can we get this merged into master asap? |
There are a lot of changes in this PR, making it difficult to review. I think you'll have better luck getting it reviewed if you focus the PR to do what the title says it should do. |
Thanks for the suggestion 👍 However, those helpers are related to the change because otherwise it is a lot of work to update all the tests manually. Due to the new error being present almost all of the tests failed. Of course I could invest more time and revert those changes in the tests but to be honest I have the feeling it would not result in my PR being merged, as I have seen very little response from the maintainers on my PR's for this repo 😕 |
I'm working on a solution to the whole error formatting problem, which is why I'm taking interest in this PR. If this repo is stale I'll just need to vendor it myself, but I would like to not repeat others work if I don't have to. It would be easier to discuss your approach if you split up the work in commits. That shouldn't be too hard to do. (I have no idea how proficient you are with git, so I'm just going to assume very basic knowledge here and give you the steps, just in case :) ) # cd to your fork
$ git stash # or whatever, just make sure your working directory is clean
$ git checkout keep-cause-errors
$ git reset @~ # undo's the commit, but leaves all changes
$ git diff # Take a glance and decide which change you want to commit first
$ git add -p # Only add changes/patches that belongs in the commit you're creating. Use h to view help
$ git commit -m "Refactor tests to use helper for error message matching" # Commit the changes
# repeat steps with diff, add, and commit until done
$ git push -f # overwrites this PR with your new commits And if you do this, you might as well drop changes like adding |
Sure no problem, I'll split it in logical commits, give me 5 minutes 😉 |
4ede71a
to
a5ac21d
Compare
I have split the PR into three separate commits, let's see what TravisCI has to say 🤞 |
a5ac21d
to
a31b4b3
Compare
Updated the first commit just to include |
Hey, sorry for disappearing, hehe. Storing the original error and making it available outside this library is a good idea. May I suggest we change the name of res := graphql.Do(params)
if res.HasErrors() {
for _, err := range res.Errors {
if err, ok := errors.Cause(err.Cause()).(interface {
AsPublicJSON() []byte
}); ok {
err.AsPublicJSON()))
}
}
} Specifically this: |
Yes Regarding the use of |
Hello there, just here to support this PR. I have the same need. Can't wait to see it merged ! |
In the context of // gqlerrors/formatted.go
type FormattedError struct {
Message string `json:"message"`
Locations []location.SourceLocation `json:"locations"`
cause error
} But from the perspective of the user facing api, // gqlerrors/formatted.go
func (g FormattedError) Error() string {
return g.Message
}
func (g FormattedError) Cause() error {
return g.cause
} I'm fine with func (g FormattedError) Error() string {
return g.Message
}
func (g FormattedError) Underlying() error {
return g.cause
} I noticed that in func FormatError(err error) FormattedError {
switch err := err.(type) {
case FormattedError:
return err
case *Error:
return FormattedError{
Message: err.Error(),
Locations: err.Locations,
cause: err // <-- or err.OriginalError (I discuss this in the last paragraph)
}
case Error:
return FormattedError{
Message: err.Error(),
Locations: err.Locations,
cause: err // <--
}
default:
return FormattedError{
Message: err.Error(),
Locations: []location.SourceLocation{},
cause: err,
}
}
} The // gqlerrors/errors.go
type Error struct {
Message string
Stack string
Nodes []ast.Node
Source *source.Source
Positions []int
Locations []location.SourceLocation
OriginalError error
} I don't know what the sources of |
Any news on this PR? It seems like a great addition to me, and apparently others too (given the duplicate in #379). The main reason I need this is two-fold: To keep error formatting of internal errors (like upstream "resource not found") in one place, and to transform panics and unexpected server errors so we don't leak internal details (which might be sensitive). It seems to me that three things remain to be fixed:
@dvic @nicolaiskogheim @chris-ramon do you think you'll get to this soon, or want to? If not, I'd be happy to take a stab at fixing the last things (probably through a new PR). |
I'm gonna go ahead and close this PR as I think it's outdated. I will keep the branch around, feel free to fork it and continue the work from there. |
No description provided.