Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/azure-cli-core/azure/cli/core/aaz/_error_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def __init__(self, json_object):
# ARM specific annotations
self.additional_info = [
TypedErrorInfo(additional_info["type"], additional_info["info"])
for additional_info in self.get_object_prop(json_object, self.ADDITIONALINFO_LABEL, [])
for additional_info in self.get_object_prop(json_object, self.ADDITIONALINFO_LABEL, []) or []
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If ADDITIONALINFO_LABEL can be present but null, do we want additional_info to end up as None or consistently as an empty list? I don’t have a preference.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a workaround to make it iterable in the list comprehension, previously there is an implicit error:

TypeError: 'NoneType' object is not iterable

btw, the actual logic of additional_info is

if self.additional_info:
error_str += "\nAdditional Information:"
for error_info in self.additional_info:
error_str += str(error_info)
.

]

def __str__(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
import unittest

from azure.cli.core.aaz._error_format import AAZMgmtErrorFormat


class TestMgmtErrorFormat(unittest.TestCase):
def test_additional_info_is_null(self):
response = {
"code": "BadRequest",
"message": "Test.",
"target": None,
"details": None,
"additionalInfo": None
}

error = AAZMgmtErrorFormat(response)
self.assertTrue(str(error) == '(BadRequest) Test.\nCode: BadRequest\nMessage: Test.')