Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/graphql/error/located_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import TYPE_CHECKING, Collection

from ..pyutils import inspect
from ..language.source import is_source, Source
from .graphql_error import GraphQLError

if TYPE_CHECKING:
Expand Down Expand Up @@ -39,7 +40,9 @@ def located_error(
except AttributeError:
message = str(original_error)
try:
source = original_error.source # type: ignore
source = original_error.source
if not is_source(source):
source = Source(source) if isinstance(source, str) else None
except AttributeError:
source = None
try:
Expand Down
8 changes: 8 additions & 0 deletions tests/error/test_located_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ def __init__(self):
super().__init__()

assert str(located_error(LazyError())) == "lazy"

def handles_error_with_str_source():
class CustomException(Exception):
def __init__(self, message, source):
super().__init__(message)
self.source = source
e = located_error(CustomException("msg", "source"))
assert e.source and e.source.get_location(0)
Loading