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

Bugfix: Cast error message to string to handle proxy objects #175

Merged
merged 1 commit into from Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/graphql/error/located_error.py
Expand Up @@ -29,7 +29,7 @@ def located_error(
return original_error
try:
# noinspection PyUnresolvedReferences
message = original_error.message # type: ignore
message = str(original_error.message) # type: ignore
except AttributeError:
message = str(original_error)
try:
Expand Down
23 changes: 23 additions & 0 deletions tests/error/test_located_error.py
Expand Up @@ -2,6 +2,8 @@

from graphql.error import GraphQLError, located_error

from ..utils import dedent


def describe_located_error():
def throws_without_an_original_error():
Expand All @@ -23,3 +25,24 @@ def does_not_pass_through_elasticsearch_like_errors():
e = Exception("I am from elasticsearch")
cast(Any, e).path = "/something/feed/_search"
assert located_error(e, [], []) is not e

def handles_proxy_error_messages():
class ProxyString:
def __init__(self, value):
self.value = value

def __str__(self):
return self.value

class MyError(Exception):
def __init__(self):
self.message = ProxyString("Example error")
super().__init__()

error = located_error(MyError(), [], [])

assert str(error) == dedent(
"""
Example error
"""
)