Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 17be672

Browse files
authored
Fix AttributeError on exception with field source (#240)
1 parent fa8f9b5 commit 17be672

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

‎src/graphql/error/located_error.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import TYPE_CHECKING, Collection
77

88
from ..pyutils import inspect
9+
from ..language.source import is_source, Source
910
from .graphql_error import GraphQLError
1011

1112
if TYPE_CHECKING:
@@ -39,7 +40,9 @@ def located_error(
3940
except AttributeError:
4041
message = str(original_error)
4142
try:
42-
source = original_error.source # type: ignore
43+
source = original_error.source
44+
if not is_source(source):
45+
source = Source(source) if isinstance(source, str) else None
4346
except AttributeError:
4447
source = None
4548
try:

‎tests/error/test_located_error.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,11 @@ def __init__(self):
3535
super().__init__()
3636

3737
assert str(located_error(LazyError())) == "lazy"
38+
39+
def handles_error_with_str_source():
40+
class CustomException(Exception):
41+
def __init__(self, message, source):
42+
super().__init__(message)
43+
self.source = source
44+
e = located_error(CustomException("msg", "source"))
45+
assert e.source and e.source.get_location(0)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /