From 193cea0c1b05f406e680c73360773616d4e9a790 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Thu, 22 Apr 2021 11:00:09 -0700 Subject: [PATCH 1/5] show detailed error --- sdk/core/azure-core/azure/core/exceptions.py | 5 +++-- sdk/core/azure-core/tests/test_exceptions.py | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/sdk/core/azure-core/azure/core/exceptions.py b/sdk/core/azure-core/azure/core/exceptions.py index db55b8487273..941e4bb4c15a 100644 --- a/sdk/core/azure-core/azure/core/exceptions.py +++ b/sdk/core/azure-core/azure/core/exceptions.py @@ -160,13 +160,14 @@ def error(self): return self def __str__(self): - return "({}) {}".format(self.code, self.message) + return self.message_details() def message_details(self): """Return a detailled string of the error. """ # () -> str - error_str = "Code: {}".format(self.code) + error_str = "({}) {}".format(self.code, self.message) + error_str += "\nCode: {}".format(self.code) error_str += "\nMessage: {}".format(self.message) if self.target: error_str += "\nTarget: {}".format(self.target) diff --git a/sdk/core/azure-core/tests/test_exceptions.py b/sdk/core/azure-core/tests/test_exceptions.py index 171c891d6323..85b414a16b93 100644 --- a/sdk/core/azure-core/tests/test_exceptions.py +++ b/sdk/core/azure-core/tests/test_exceptions.py @@ -122,8 +122,8 @@ def test_deserialized_httpresponse_error_code(self): } response = _build_response(json.dumps(message).encode("utf-8")) error = FakeHttpResponse(response, FakeErrorOne()) - assert error.message == "(FakeErrorOne) A fake error" - assert str(error.error) == "(FakeErrorOne) A fake error" + assert "(FakeErrorOne) A fake error" in error.message + assert "(FakeErrorOne) A fake error" in str(error.error) assert error.error.code == "FakeErrorOne" assert error.error.message == "A fake error" assert error.response is response @@ -149,8 +149,8 @@ def test_deserialized_httpresponse_error_message(self): } response = _build_response(json.dumps(message).encode("utf-8")) error = FakeHttpResponse(response, FakeErrorTwo()) - assert error.message == "(FakeErrorTwo) A different fake error" - assert str(error.error) == "(FakeErrorTwo) A different fake error" + assert "(FakeErrorTwo) A different fake error" in error.message + assert "(FakeErrorTwo) A different fake error" in str(error.error) assert error.error.code == "FakeErrorTwo" assert error.error.message == "A different fake error" assert error.response is response From 3904ed56c58f4cd71be8e083450263266f09a2a9 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Fri, 30 Apr 2021 12:10:15 -0700 Subject: [PATCH 2/5] update --- sdk/core/azure-core/azure/core/exceptions.py | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/sdk/core/azure-core/azure/core/exceptions.py b/sdk/core/azure-core/azure/core/exceptions.py index 941e4bb4c15a..5792531f3ea4 100644 --- a/sdk/core/azure-core/azure/core/exceptions.py +++ b/sdk/core/azure-core/azure/core/exceptions.py @@ -107,6 +107,27 @@ class ODataV4Format(object): http://docs.oasis-open.org/odata/odata-json-format/v4.0/os/odata-json-format-v4.0-os.html#_Toc372793091 + Example of JSON: + error": { + "code": "ValidationError", + "message": "One or more fields contain incorrect values: ", + "details": [ + { + "code": "ValidationError", + "target": "representation", + "message": "Parsing error(s): String '' does not match regex pattern '^[^{}/ :]+(?: :\\\\d+)?$'. + Path 'host', line 1, position 297." + }, + { + "code": "ValidationError", + "target": "representation", + "message": "Parsing error(s): The input OpenAPI file is not valid for the OpenAPI specificate + https: //github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md + (schema https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json)." + } + ] + } + :param dict json_object: A Python dict representing a ODataV4 JSON :ivar str ~.code: Its value is a service-defined error code. This code serves as a sub-status for the HTTP error code specified in the response. From 62ab399fa22f20b7c391eb20416c8261ba6f1341 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Tue, 4 May 2021 09:34:32 -0700 Subject: [PATCH 3/5] update --- sdk/core/azure-core/azure/core/exceptions.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sdk/core/azure-core/azure/core/exceptions.py b/sdk/core/azure-core/azure/core/exceptions.py index 5792531f3ea4..5889cb92411f 100644 --- a/sdk/core/azure-core/azure/core/exceptions.py +++ b/sdk/core/azure-core/azure/core/exceptions.py @@ -181,14 +181,17 @@ def error(self): return self def __str__(self): - return self.message_details() + return "({}) {}\n{}".format( + self.code, + self.message, + self.message_details() + ) def message_details(self): """Return a detailled string of the error. """ # () -> str - error_str = "({}) {}".format(self.code, self.message) - error_str += "\nCode: {}".format(self.code) + error_str = "Code: {}".format(self.code) error_str += "\nMessage: {}".format(self.message) if self.target: error_str += "\nTarget: {}".format(self.target) From 748171ff233c3354d7d94ada66f8627d99b558cc Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Tue, 4 May 2021 09:47:03 -0700 Subject: [PATCH 4/5] update --- sdk/core/azure-core/azure/core/exceptions.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sdk/core/azure-core/azure/core/exceptions.py b/sdk/core/azure-core/azure/core/exceptions.py index 5889cb92411f..90730d7e9501 100644 --- a/sdk/core/azure-core/azure/core/exceptions.py +++ b/sdk/core/azure-core/azure/core/exceptions.py @@ -108,7 +108,8 @@ class ODataV4Format(object): http://docs.oasis-open.org/odata/odata-json-format/v4.0/os/odata-json-format-v4.0-os.html#_Toc372793091 Example of JSON: - error": { + + error: { "code": "ValidationError", "message": "One or more fields contain incorrect values: ", "details": [ @@ -126,7 +127,7 @@ class ODataV4Format(object): (schema https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json)." } ] - } + } :param dict json_object: A Python dict representing a ODataV4 JSON :ivar str ~.code: Its value is a service-defined error code. From 148ed3d745011139e02265e236a6b519ab8106d6 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Tue, 4 May 2021 11:23:25 -0700 Subject: [PATCH 5/5] update --- sdk/core/azure-core/azure/core/exceptions.py | 34 ++++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/sdk/core/azure-core/azure/core/exceptions.py b/sdk/core/azure-core/azure/core/exceptions.py index 90730d7e9501..4af83e9b3683 100644 --- a/sdk/core/azure-core/azure/core/exceptions.py +++ b/sdk/core/azure-core/azure/core/exceptions.py @@ -110,23 +110,23 @@ class ODataV4Format(object): Example of JSON: error: { - "code": "ValidationError", - "message": "One or more fields contain incorrect values: ", - "details": [ - { - "code": "ValidationError", - "target": "representation", - "message": "Parsing error(s): String '' does not match regex pattern '^[^{}/ :]+(?: :\\\\d+)?$'. - Path 'host', line 1, position 297." - }, - { - "code": "ValidationError", - "target": "representation", - "message": "Parsing error(s): The input OpenAPI file is not valid for the OpenAPI specificate - https: //github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md - (schema https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json)." - } - ] + "code": "ValidationError", + "message": "One or more fields contain incorrect values: ", + "details": [ + { + "code": "ValidationError", + "target": "representation", + "message": "Parsing error(s): String '' does not match regex pattern '^[^{}/ :]+(?: :\\\\d+)?$'. + Path 'host', line 1, position 297." + }, + { + "code": "ValidationError", + "target": "representation", + "message": "Parsing error(s): The input OpenAPI file is not valid for the OpenAPI specificate + https: //github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md + (schema https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json)." + } + ] } :param dict json_object: A Python dict representing a ODataV4 JSON