diff --git a/src/graphql/error/graphql_error.py b/src/graphql/error/graphql_error.py index 75e34b6a..a13a7844 100644 --- a/src/graphql/error/graphql_error.py +++ b/src/graphql/error/graphql_error.py @@ -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: diff --git a/tests/error/test_graphql_error.py b/tests/error/test_graphql_error.py index 6c4689da..11bf8df7 100644 --- a/tests/error/test_graphql_error.py +++ b/tests/error/test_graphql_error.py @@ -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():