-
-
Notifications
You must be signed in to change notification settings - Fork 140
No line numbers in errors #36
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
Comments
Can you post a small example with code, actual output and expected output? |
This is likely a weakness in my Python understanding - I was expecting the traceback to added to logger through logger.error(err). In the end, I got the trackback from the error object as above. I would have thought that the text representation of the error would at least have the file and line number (not the full traceback), or am I wrong in that assumption? There doesn't seem to be anything in the manual regarding error handling, nor the anatomy of the GraphQL error object, unless I'm mistaken? |
@andrewspode Line numbers in Python code are part of the traceback which is not part of the string representation of an error. You can create your own logging The reference on Read the Docs was broken. The anatomy of the GraphQL error object is here now: https://graphql-core-next.readthedocs.io/en/latest/modules/error.html GraphQL-core is the low-level library that provides the errors - everything else regarding error handling should be implemented and documented on the levels higher up which are implementing the GraphQL server (packages like Graphene-Django), depending on the environment (development, production etc.) |
I think this would add the traceback to the log message:
logger.error(err, exc_info=err)
st 12. 6. 2019 v 12:02 odesílatel Andrew Spode <[email protected]>
napsal:
… if result.errors:
data['errors'] = []
for err in result.errors:
data['errors'].append(str(err))
logger.error(err)
# TODO: This should be going to logger
traceback.print_tb(err.__traceback__)
This is likely a weakness in my Python understanding - I was expecting the
traceback to added to logger through logger.error(err). In the end, I got
the trackback from the error object as above.
|
@messa Nice! That looks like the simplest solution. Just looked it up in the Python docs: There are three keyword arguments which are inspected:
|
I had previously tried using sys.exc_info() but because I wasn't handling the original error, it gave me no results. @messa - your solution is by far the simplest and neatest - thank you! Glad to see Errors are back in the documentation - that clears some things up. Hopefully this thread will come up in Google for other people suffering with the same issue - it's very hard to debug resolvers without line numbers! Alternatively, a little paragraph on this in your documents wouldn't go amiss. |
graphql-core@2 used to, as for as I can see, log stack traces of Python errors automatically, and @3 no longer does. I think that is a real loss; Often, an exception message just does not tell you where the error is, and having to go in and manually figure out how to use the traceback module to access the stack trace is unnecessarily complicated. |
@miracle2k: As messa pointed out, it suffices to call |
@Cito Maybe so. But still, I think this is decidedly a downgrade in the dev experience compared to @2. Literally every developer is going to have an exception in a resolver at some point, would not see any useful output on the console, and would then have to figure out how to see what is going on, and how to fix it. Maybe in the future, when adapted to @3, libraries such as I mean I can see both sides here, but it was certainly very frustrating to deal with this when upgrading. |
I see this issue here complaining of lack of traceback, apparently fixed in 1.0.2
#23
My experience on 1.0.5 is that I only get a text representation of the error, and no line number of where the problem lies, which makes debugging very hard.
name 'error' is not defined
GraphQL request (32:2)
31:
32: {info}
I only get the place in the query that it's failed - which doesn't help enough.
The text was updated successfully, but these errors were encountered: