From e4098e1d1341fc037d0faa13c880d3329f4870aa Mon Sep 17 00:00:00 2001 From: Mayank Raj Date: Wed, 23 Oct 2024 13:56:10 +0200 Subject: [PATCH] minor fix in error message --- databricks/sdk/errors/parser.py | 4 +++- tests/test_errors.py | 22 ++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/databricks/sdk/errors/parser.py b/databricks/sdk/errors/parser.py index 3408964fe..66aa8da60 100644 --- a/databricks/sdk/errors/parser.py +++ b/databricks/sdk/errors/parser.py @@ -38,7 +38,9 @@ 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}```' + f' Config: host={response.request.url}, status_code={response.status_code}' + ) class _Parser: diff --git a/tests/test_errors.py b/tests/test_errors.py index 881f016f3..9814cb3f3 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -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 + @@ -112,11 +118,8 @@ def make_private_link_response() -> requests.Response: (fake_response('GET', 400, '
Worker environment not ready
'), 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({ @@ -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) assert isinstance(e.value, expected_error) assert str(e.value) == expected_message + +