Skip to content

Commit 126d041

Browse files
stephen-zhaohashhar
authored andcommitted
Make error_location optional
Add more None checks
1 parent 4354277 commit 126d041

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

trino/exceptions.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,15 @@ def message(self) -> str:
108108
return self._error.get("message", "Trino did not return an error message")
109109

110110
@property
111-
def error_location(self) -> Tuple[int, int]:
112-
location = self._error["errorLocation"]
113-
return (location["lineNumber"], location["columnNumber"])
111+
def error_location(self) -> Optional[Tuple[int, int]]:
112+
location = self._error.get("errorLocation", None)
113+
if location is None:
114+
return None
115+
line_number = location.get("lineNumber", None)
116+
column_number = location.get("columnNumber", None)
117+
if line_number is None or column_number is None:
118+
return None
119+
return (line_number, column_number)
114120

115121
@property
116122
def query_id(self) -> Optional[str]:

0 commit comments

Comments
 (0)