Skip to content

Commit a98360a

Browse files
authored
FIX: Show DDBC error messages in exceptions for unknown codes (#40)
* FIX: Show ddbc error messages in exceptions for unknown codes * fixing tests
1 parent 08ef046 commit a98360a

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

mssql_python/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,6 @@ def raise_exception(sqlstate: str, ddbc_error: str) -> None:
645645
logger.error(exception_class)
646646
raise exception_class
647647
raise DatabaseError(
648-
driver_error="An error occurred with SQLSTATE code",
649-
ddbc_error=f"Unknown DDBC error: {sqlstate}",
648+
driver_error=f"An error occurred with SQLSTATE code: {sqlstate}",
649+
ddbc_error=f"{ddbc_error}" if ddbc_error else f"Unknown DDBC error",
650650
)

tests/test_005_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_not_supported_error_exception():
7171
def test_unknown_error_exception():
7272
with pytest.raises(DatabaseError) as excinfo:
7373
raise_exception('99999', 'Unknown error')
74-
assert str(excinfo.value) == "Driver Error: An error occurred with SQLSTATE code; DDBC Error: Unknown DDBC error: 99999"
74+
assert str(excinfo.value) == "Driver Error: An error occurred with SQLSTATE code: 99999; DDBC Error: Unknown error"
7575

7676
def test_syntax_error(cursor):
7777
with pytest.raises(ProgrammingError) as excinfo:

0 commit comments

Comments
 (0)