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

Exceptions in resolver are caught (no traceback) #23

Closed
ceelian opened this issue Feb 25, 2019 · 4 comments
Closed

Exceptions in resolver are caught (no traceback) #23

ceelian opened this issue Feb 25, 2019 · 4 comments

Comments

@ceelian
Copy link

ceelian commented Feb 25, 2019

Version:
GraphQL-core-next 1.0.1
Python 3.7.1

Current Behaviour:

Exceptions in resolvers are caught by default and the traceback of the original_error doesn't help debugging.

Traceback output of log.exception('', exc_info=result.errors[0].original_error)

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/graphql/execution/execute.py", line 664, in complete_value_catching_error
    return_type, field_nodes, info, path, result
  File "/usr/local/lib/python3.6/site-packages/graphql/execution/execute.py", line 731, in complete_value
    raise result
graphql.error.graphql_error.GraphQLError: My exception

Expected Behaviour:

  1. There is a flag raise_exception which switches if exceptions are caught or if they are raised out of the library resolver.

  2. The traceback of the original_errors is meaningful: leads to the source line where the exception occurred.

@Cito
Copy link
Member

Cito commented Mar 1, 2019

@ceelian - thanks for the feedback. Changeset e0bb443 should improve this.

Here is an example how you can get error tracebacks now:

from traceback import print_tb
from graphql import *

def bad_resolver(obj, info):
    raise RuntimeError("the runtime error")

schema = GraphQLSchema(query=GraphQLObjectType(
    name='RootQueryType',
    fields={'bad': GraphQLField(GraphQLString, resolve=bad_resolver)}))

error = graphql_sync(schema, '{ bad }').errors[0]
original_error = error.original_error

print(error)
print_tb(error.__traceback__)

Output:

the runtime error

GraphQL request (1:3)
1: { bad }
     ^

  File ".../execute.py", line 664, in complete_value_catching_error
    return_type, field_nodes, info, path, result
  File ".../execute.py", line 731, in complete_value
    raise result
  File "../execute.py", line 619, in resolve_field_value_or_error
    result = resolve_fn(source, info, **args)
  File "test_graphql.py", line 7, in bad_resolver
    raise RuntimeError("the runtime error")

Will release an upate with this improvement soon.

@ceelian
Copy link
Author

ceelian commented Mar 1, 2019

Great, thank you for the improvement!

@ezyang
Copy link

ezyang commented Mar 6, 2019

Thank you, I was affected by this too.

@Cito
Copy link
Member

Cito commented Mar 10, 2019

Version 1.0,2 with this fix has now been released on PyPI.

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

No branches or pull requests

3 participants