Skip to content

Commit a5450f0

Browse files
committed
Cast error message to string to handle proxy objects
1 parent b3721c9 commit a5450f0

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/graphql/error/located_error.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def located_error(
2929
return original_error
3030
try:
3131
# noinspection PyUnresolvedReferences
32-
message = original_error.message # type: ignore
32+
message = str(original_error.message) # type: ignore
3333
except AttributeError:
3434
message = str(original_error)
3535
try:

tests/error/test_located_error.py

+23
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from graphql.error import GraphQLError, located_error
44

5+
from ..utils import dedent
6+
57

68
def describe_located_error():
79
def throws_without_an_original_error():
@@ -23,3 +25,24 @@ def does_not_pass_through_elasticsearch_like_errors():
2325
e = Exception("I am from elasticsearch")
2426
cast(Any, e).path = "/something/feed/_search"
2527
assert located_error(e, [], []) is not e
28+
29+
def handles_proxy_error_messages():
30+
class ProxyString:
31+
def __init__(self, value):
32+
self.value = value
33+
34+
def __str__(self):
35+
return self.value
36+
37+
class MyError(Exception):
38+
def __init__(self):
39+
self.message = ProxyString("Example error")
40+
super().__init__()
41+
42+
error = located_error(MyError(), [], [])
43+
44+
assert str(error) == dedent(
45+
"""
46+
Example error
47+
"""
48+
)

0 commit comments

Comments
 (0)