Skip to content

Include stack trace in errors #277

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

gaelollivier
Copy link

Hey,

Currently, if a runtime error occurs during the execution of a query, the only information available looks like this:

{
  "data": null,
  "errors": [
    {
      "message": "runtime error: invalid memory address or nil pointer dereference",
      "locations": []
    }
  ]
}

Which is quite tricky to debug.

This PR adds a "StackTrace" field to the FormattedError object. This field is not exposed to the JSON version, so it doesn't expose possibly sensible debug information but can be used for logs.
Currently the field is only populated in one place but I guess it makes sense to populate it wherever there is a recover() call.
Because the call to debug.Stack() may be expensive, maybe we should add an option to enable/disable it ? Not sure how we should expose this.

Do you think this feature make sense ?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.004%) to 81.037% when pulling ba52787 on gaelduplessix:include-trace-in-errors into 1c504cf on graphql-go:master.

@coveralls
Copy link

coveralls commented Feb 5, 2018

Coverage Status

Coverage increased (+0.03%) to 81.043% when pulling 6748b1e on gaelduplessix:include-trace-in-errors into 1e23489 on graphql-go:master.

@dvic
Copy link
Contributor

dvic commented Feb 5, 2018

I just went with the approach of letting it implement the Causer interface: https://github.com/qdentity/graphql-go/blob/master/gqlerrors/formatted.go

In this way, you can extract your own errors thrown in the resolvers and render them appropriately.

@gaelollivier
Copy link
Author

@dvic Indeed, sounds more generic.

Still, I think the trace should be included anyway. In my case, I had a runtime exception happening inside the lib (this is probably a bug btw, if performing a mutation query when none is defined in the schema)

So to include the stack trace, we would build a custom error type that returns the trace in the Cause() method ? Or the user could retrieve the underlying error type and call Trace() on it directly ?

@dvic
Copy link
Contributor

dvic commented Feb 5, 2018

@gaelduplessix I modified that code to use github.com/pkg/errors instead of the standard library errors package. The package github.com/pkg/errors stores the stack trace for you (you can see it when you print the error with %v or %+v).

@dvic
Copy link
Contributor

dvic commented Feb 5, 2018

By the way, https://github.com/qdentity/graphql-go also contains changes w.r.t. how resolvers are called. I took the changes from #213 and added the concurrent resolving of list values #132. This is a perfect match with https://github.com/nicksrandall/dataloader. There were some data races but I managed to fix these as well, all tests are passing with the -race flag included. If anybody is interested in this I can open a PR.

@gaelollivier
Copy link
Author

@dvic Oh, sounds neat :) Well, the error improvement seems quite an isolated issue. Would it make sense to extract it to another PR ?

@dvic
Copy link
Contributor

dvic commented Feb 5, 2018

:) Those fixes are only useful/needed if #213 or #132 are merged, however, it is not clear at the moment which path will be chosen. So it's best to wait until a decision has been made before merging those fixes into the appropriate branch.

I did however submit a PR (#278) just now that makes sure the tests check for race conditions, so the issue is caught as soon as concurrency is added to the project.

@gaelollivier
Copy link
Author

Well, improvements on errors are useful on their own, wouldn't it make sense to have these changes isolated from the rest (adding concurrency to the resolver) so they can be merged sooner ?

Is there any ETA on when #213 or #132 are going to be merged ? (I'm quite new to this project so I don't really have any context on how the development is going)

@dvic
Copy link
Contributor

dvic commented Feb 5, 2018

I have no idea on the ETA of either #213 or #132, but I'll cook up a PR for the changes w.r.t. the errors (it's basically this commit).

@dvic
Copy link
Contributor

dvic commented Feb 5, 2018

Created PR #279 for the changes of embedding errors in FormattedError.

@dvic
Copy link
Contributor

dvic commented Feb 7, 2018

@gaelduplessix did you have time to check out #279? Will it work for your use case?

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.

4 participants