Skip to content

Commit

Permalink
Store snowflake-connector-python error in SnowflakeSQLException
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-bchinn committed Nov 16, 2023
1 parent d347bc2 commit 166abfe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 1.10.1 (TBD)

### New Features

- Add the `conn_error` attribute to `SnowflakeSQLException` that stores the whole underlying exception from `snowflake-connector-python`

### Bug Fixes

- DataFrame column names qouting check now supports newline characters.
Expand Down
18 changes: 2 additions & 16 deletions src/snowflake/snowpark/_internal/error_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,27 +316,13 @@ def SQL_PYTHON_REPORT_JOIN_AMBIGUOUS(
def SQL_EXCEPTION_FROM_PROGRAMMING_ERROR(
pe: ProgrammingError,
) -> SnowparkSQLException:
query = getattr(pe, "query", None)
return SnowparkSQLException(
pe.msg,
error_code="1304",
sfqid=pe.sfqid,
query=query,
sql_error_code=pe.errno,
raw_message=pe.raw_msg,
)
return SnowparkSQLException(pe.msg, error_code="1304", conn_error=pe)

@staticmethod
def SQL_EXCEPTION_FROM_OPERATIONAL_ERROR(
oe: OperationalError,
) -> SnowparkSQLException:
return SnowparkSQLException(
oe.msg,
error_code="1305",
sfqid=oe.sfqid,
sql_error_code=oe.errno,
raw_message=oe.raw_msg,
)
return SnowparkSQLException(oe.msg, error_code="1305", conn_error=oe)

# Server Error Messages 04XX

Expand Down
12 changes: 8 additions & 4 deletions src/snowflake/snowpark/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import logging
from typing import Optional

from snowflake.connector.errors import Error as ConnectorError

_logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -79,17 +81,19 @@ def __init__(
message: str,
*,
error_code: Optional[str] = None,
conn_error: Optional[ConnectorError] = None,
sfqid: Optional[str] = None,
query: Optional[str] = None,
sql_error_code: Optional[int] = None,
raw_message: Optional[str] = None,
) -> None:
super().__init__(message, error_code=error_code)

self.sfqid: Optional[str] = sfqid
self.query: Optional[str] = query
self.sql_error_code = sql_error_code
self.raw_message = raw_message
self.conn_error = conn_error
self.sfqid = sfqid or getattr(self.conn_error, "sfqid", None)
self.query = query or getattr(self.conn_error, "query", None)
self.sql_error_code = sql_error_code or getattr(self.conn_error, "errno", None)
self.raw_message = raw_message or getattr(self.conn_error, "raw_msg", None)

pretty_error_code = f"({self.error_code}): " if self.error_code else ""
pretty_sfqid = f"{self.sfqid}: " if self.sfqid else ""
Expand Down

0 comments on commit 166abfe

Please sign in to comment.