Skip to content

Commit

Permalink
Small fix in trino.exceptions.TrinoQueryError
Browse files Browse the repository at this point in the history
  • Loading branch information
damian3031 committed Jan 18, 2023
1 parent f58375e commit 7998fb7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion trino/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ def execute(
call fetch() until finished is true.
"""
if self.cancelled:
raise exceptions.TrinoUserError("Query has been cancelled", self.query_id)
raise exceptions.TrinoUserError({"message": "Query has been cancelled"}, self.query_id)

response = self._request.post(self._sql, additional_http_headers)
status = self._request.process(response)
Expand Down
21 changes: 12 additions & 9 deletions trino/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,38 +72,41 @@ class TrinoDataError(NotSupportedError):


class TrinoQueryError(Error):
def __init__(self, error: Any, query_id: Optional[str] = None) -> None:
def __init__(self, error: Dict[str, Any], query_id: Optional[str] = None) -> None:
self._error = error
self._query_id = query_id

@property
def error_code(self) -> Optional[int]:
return self._error.get("errorCode", None)
return self._error.get("errorCode")

@property
def error_name(self) -> Optional[str]:
return self._error.get("errorName", None)
return self._error.get("errorName")

@property
def error_type(self) -> Optional[str]:
return self._error.get("errorType", None)
return self._error.get("errorType")

@property
def error_exception(self) -> Optional[str]:
return self.failure_info.get("type", None) if self.failure_info else None
return self.failure_info.get("type") if self.failure_info else None

@property
def failure_info(self) -> Optional[Dict[str, Any]]:
return self._error.get("failureInfo", None)
return self._error.get("failureInfo")

@property
def message(self) -> str:
return self._error.get("message", "Trino did not return an error message")

@property
def error_location(self) -> Tuple[int, int]:
location = self._error["errorLocation"]
return (location["lineNumber"], location["columnNumber"])
def error_location(self) -> Optional[Tuple[int, int]]:
location = self._error.get("errorLocation")
if location:
return (location["lineNumber"], location["columnNumber"])
else:
return None

@property
def query_id(self) -> Optional[str]:
Expand Down

0 comments on commit 7998fb7

Please sign in to comment.