Skip to content

Commit

Permalink
minor fix in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
dsculptor committed Oct 23, 2024
1 parent d3b85cb commit bfe9b0b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion databricks/sdk/errors/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def _unknown_error(response: requests.Response) -> str:
return (
'This is likely a bug in the Databricks SDK for Python or the underlying '
'API. Please report this issue with the following debugging information to the SDK issue tracker at '
f'https://github.com/databricks/databricks-sdk-go/issues. Request log:```{request_log}```')
f'https://github.com/databricks/databricks-sdk-py/issues. Request log:```{request_log}```'
)


class _Parser:
Expand Down
24 changes: 15 additions & 9 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ def make_private_link_response() -> requests.Response:
subclass_test_cases = [(fake_valid_response('GET', x[0], x[1], 'nope'), x[2], 'nope')
for x in base_subclass_test_cases]

UNABLE_TO_PARSE_RESPONSE_ERROR = (
'unable to parse response. This is likely a bug in the Databricks SDK for Python or the underlying API. '
'Please report this issue with the following debugging information to the SDK issue tracker at '
'https://github.com/databricks/databricks-sdk-py/issues. Request log:```GET /api/2.0/service\n'
'< {status_code} {reason}\n< {response_body}```'
)

@pytest.mark.parametrize(
'response, expected_error, expected_message', subclass_test_cases +
Expand Down Expand Up @@ -112,11 +118,8 @@ def make_private_link_response() -> requests.Response:
(fake_response('GET', 400, '<pre>Worker environment not ready</pre>'), errors.BadRequest,
'Worker environment not ready'),
(fake_response('GET', 400, 'this is not a real response'), errors.BadRequest,
('unable to parse response. This is likely a bug in the Databricks SDK for Python or the underlying API. '
'Please report this issue with the following debugging information to the SDK issue tracker at '
'https://github.com/databricks/databricks-sdk-go/issues. Request log:```GET /api/2.0/service\n'
'< 400 Bad Request\n'
'< this is not a real response```')),
UNABLE_TO_PARSE_RESPONSE_ERROR.format(status_code=400, reason='Bad Request', response_body='this is not a real response')
),
(fake_response(
'GET', 404,
json.dumps({
Expand All @@ -125,14 +128,17 @@ def make_private_link_response() -> requests.Response:
'schemas': ['urn:ietf:params:scim:api:messages:2.0:Error']
})), errors.NotFound, 'None Group with id 1234 is not found'),
(fake_response('GET', 404, json.dumps("This is JSON but not a dictionary")), errors.NotFound,
'unable to parse response. This is likely a bug in the Databricks SDK for Python or the underlying API. Please report this issue with the following debugging information to the SDK issue tracker at https://github.com/databricks/databricks-sdk-go/issues. Request log:```GET /api/2.0/service\n< 404 Not Found\n< "This is JSON but not a dictionary"```'
UNABLE_TO_PARSE_RESPONSE_ERROR.format(status_code=404, reason='Not Found', response_body='"This is JSON but not a dictionary"')
),
(fake_raw_response('GET', 404, b'\x80'), errors.NotFound,
'unable to parse response. This is likely a bug in the Databricks SDK for Python or the underlying API. Please report this issue with the following debugging information to the SDK issue tracker at https://github.com/databricks/databricks-sdk-go/issues. Request log:```GET /api/2.0/service\n< 404 Not Found\n< �```'
)])
UNABLE_TO_PARSE_RESPONSE_ERROR.format(status_code=404, reason='Not Found', response_body='�')
)]
)
def test_get_api_error(response, expected_error, expected_message):
parser = errors._Parser()
with pytest.raises(errors.DatabricksError) as e:
raise parser.get_api_error(response)
raise parser.get_api_error(response)
assert isinstance(e.value, expected_error)
assert str(e.value) == expected_message


0 comments on commit bfe9b0b

Please sign in to comment.