Skip to content

Commit

Permalink
Cast error message to string to handle proxy objects
Browse files Browse the repository at this point in the history
  • Loading branch information
jkimbo committed Jun 8, 2022
1 parent b3721c9 commit 6a9f820
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/graphql/error/graphql_error.py
Expand Up @@ -173,7 +173,7 @@ def __str__(self) -> str:
# Lazy import to avoid a cyclic dependency between error and language
from ..language.print_location import print_location, print_source_location

output = [self.message]
output = [str(self.message)]

if self.nodes:
for node in self.nodes:
Expand Down
24 changes: 24 additions & 0 deletions tests/error/test_graphql_error.py
Expand Up @@ -351,6 +351,30 @@ def prints_an_error_with_nodes_from_different_sources():
"""
)

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

def __str__(self):
return self.value

error = GraphQLError(ProxyString("Example error")) # type: ignore

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

error = GraphQLError(ValueError(ProxyString("Example value error"))) # type: ignore # noqa: E501

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


def describe_formatted():
def deprecated_formats_an_error_using_format_error():
Expand Down

0 comments on commit 6a9f820

Please sign in to comment.