graphql-core-legacy icon indicating copy to clipboard operation
graphql-core-legacy copied to clipboard

Unable to locate original location of Exception

Open Drarok opened this issue 7 years ago • 3 comments

In executor.py, there is the following code:

if isinstance(result, Exception):
    raise GraphQLLocatedError(field_asts, original_error=result, path=path)

This appears to swallow the original error (result) as it doesn't appear in any tracebacks, leading me to lose my mind trying to work out where an error is actually being thrown. In my local install I have changed it to this in order to chain the exceptions:

if isinstance(result, Exception):
    raise GraphQLLocatedError(field_asts, original_error=result, path=path) from result

This gives me the full original exception's stack trace to look at when I'm debugging, and allows me to regain some sanity. I don't know if there any any knock-on effects though, which is why I didn't create this as a pull request. I'd love to hear your thoughts!

Drarok avatar Sep 21 '18 15:09 Drarok

Thanks for taking the time to post this and contribute a solution!

I don't have any insight on the problem at hand directly (your code looks good!) but one small problem you'll need to look into when doing a PR is compatibility with Python 2. You probably want to be using https://pythonhosted.org/six/#six.raise_from instead of raise X from Y. The project is already using six for compatibility.

If we fix compatibility I don't know of any bad side effects, so if it helps you its probably useful and deserves a PR!

wapiflapi avatar Sep 22 '18 20:09 wapiflapi

Unfortunately, @Drarok's solution didn't work for me. It is incredibly frustrating not having a stack trace in the logs.

feus4177 avatar Dec 17 '18 23:12 feus4177

@feus4177 As a temporary workaround I changed this function at executor.py like

            def handle_error(error):
                import traceback; traceback.print_tb(error.original_error.__traceback__)  # this line has been inserted
                # type: (Union[GraphQLError, GraphQLLocatedError]) -> Optional[Any]
                traceback = completed._traceback  # type: ignore
                exe_context.report_error(error, traceback)
                return None

and it now prints stack traces.

ykiu avatar Mar 06 '19 14:03 ykiu