diff --git a/graphql/error/located_error.py b/graphql/error/located_error.py index 87ded24e..9111f764 100644 --- a/graphql/error/located_error.py +++ b/graphql/error/located_error.py @@ -9,7 +9,10 @@ class GraphQLLocatedError(GraphQLError): def __init__(self, nodes, original_error=None): if original_error: - message = str(original_error) + try: + message = str(original_error) + except UnicodeEncodeError: + message = original_error.message.encode('utf-8') else: message = 'An unknown error occurred.' diff --git a/graphql/execution/tests/test_located_error.py b/graphql/execution/tests/test_located_error.py new file mode 100644 index 00000000..0ff9530f --- /dev/null +++ b/graphql/execution/tests/test_located_error.py @@ -0,0 +1,23 @@ +# coding: utf-8 + +from graphql import GraphQLField +from graphql import GraphQLObjectType +from graphql import GraphQLSchema +from graphql import GraphQLString +from graphql import execute +from graphql import parse +from graphql.error import GraphQLLocatedError + + +def test_unicode_error_message(): + ast = parse('query Example { unicode }') + + def resolver(context, *_): + raise Exception(u'UNIÇODÉ!') + + Type = GraphQLObjectType('Type', { + 'unicode': GraphQLField(GraphQLString, resolver=resolver), + }) + + result = execute(GraphQLSchema(Type), ast) + assert isinstance(result.errors[0], GraphQLLocatedError) \ No newline at end of file