Skip to content

Commit c409c3b

Browse files
authored
Refactor semantic error handling and add tests for validation (#561)
1 parent 6bbba52 commit c409c3b

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111
- Added `py.typed` markers
12+
- Fixed semantic error handling
1213

1314
## [4.6.1] - 2024-09-30
1415

azure-kusto-data/azure/kusto/data/exceptions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class KustoTokenParsingError(KustoStreamingQueryError):
2727
...
2828

2929

30+
SEMANTIC_ERROR_STRING = "Semantic error:"
31+
32+
3033
class KustoServiceError(KustoError):
3134
"""Raised when the Kusto service was unable to process a request."""
3235

@@ -40,14 +43,16 @@ def __init__(
4043
self.http_response = http_response
4144
self.kusto_response = kusto_response
4245

46+
self.message_text = messages if isinstance(messages, str) else "\n\n".join(repr(m) for m in messages)
47+
4348
def get_raw_http_response(self) -> "Union[requests.Response, ClientResponse, None]":
4449
"""Gets the http response."""
4550
return self.http_response
4651

4752
def is_semantic_error(self) -> bool:
4853
"""Checks if a response is a semantic error."""
4954
try:
50-
return "Semantic error:" in self.http_response.text
55+
return SEMANTIC_ERROR_STRING in self.message_text
5156
except AttributeError:
5257
return False
5358

azure-kusto-data/tests/test_e2e_data.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,16 @@ async def test_no_redirects_fail_in_client_async(self, code):
386386
with pytest.raises(KustoServiceError) as ex:
387387
await client.execute("db", "table")
388388
assert ex.value.http_response.status == code
389+
390+
def test_semantic_error(self):
391+
with self.get_client() as client:
392+
with pytest.raises(KustoServiceError) as ex:
393+
client.execute(self.test_db, "Nonexistent")
394+
assert ex.value.is_semantic_error()
395+
396+
@pytest.mark.asyncio
397+
async def test_semantic_error_async(self):
398+
async with await self.get_async_client() as client:
399+
with pytest.raises(KustoServiceError) as ex:
400+
await client.execute(self.test_db, "Nonexistent")
401+
assert ex.value.is_semantic_error()

0 commit comments

Comments
 (0)