Skip to content

Commit d978405

Browse files
author
Romulo Furtado
committed
fix(graphql-error) unicode error message
1 parent e56723a commit d978405

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

graphql/error/located_error.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ class GraphQLLocatedError(GraphQLError):
99

1010
def __init__(self, nodes, original_error=None):
1111
if original_error:
12-
message = (
13-
original_error.message.encode('utf-8')
14-
if isinstance(original_error.message, unicode)
15-
else str(original_error)
16-
)
17-
12+
try:
13+
message = str(original_error)
14+
except UnicodeEncodeError:
15+
message = original_error.message.encode('utf-8')
1816
else:
1917
message = 'An unknown error occurred.'
2018

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# coding: utf-8
2+
3+
from graphql import GraphQLField
4+
from graphql import GraphQLObjectType
5+
from graphql import GraphQLSchema
6+
from graphql import GraphQLString
7+
from graphql import execute
8+
from graphql import parse
9+
from graphql.error import GraphQLLocatedError
10+
11+
12+
def test_unicode_error_message():
13+
ast = parse('query Example { unicode }')
14+
15+
def resolver(context, *_):
16+
raise Exception(u'UNIÇODÉ!')
17+
18+
Type = GraphQLObjectType('Type', {
19+
'unicode': GraphQLField(GraphQLString, resolver=resolver),
20+
})
21+
22+
result = execute(GraphQLSchema(Type), ast)
23+
assert isinstance(result.errors[0], GraphQLLocatedError)

0 commit comments

Comments
 (0)