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
25 changes: 20 additions & 5 deletions src/azure-cli-core/azure/cli/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,25 @@ def shell_safe_json_parse(json_or_dict_string, preserve_order=False, strict=True
try:
import ast
return ast.literal_eval(json_or_dict_string)
except SyntaxError:
raise CLIError(json_ex)
except ValueError as ex:
except Exception as ex:
Copy link
Member Author

Choose a reason for hiding this comment

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

No need to distinguish between SyntaxError and ValueError.

logger.debug(ex) # log the exception which could be a python dict parsing error.
raise CLIError(json_ex) # raise json_ex error which is more readable and likely.

# Echo the JSON received by CLI
msg = "Failed to parse JSON: {}\nError detail: {}".format(json_or_dict_string, json_ex)

# Recommendation for all shells
from azure.cli.core.azclierror import InvalidArgumentValueError
recommendation = "The JSON may have been parsed by the shell. See " \
"https://docs.microsoft.com/cli/azure/use-cli-effectively#quoting-issues"

# Recommendation especially for PowerShell
parent_proc = get_parent_proc_name().lower()
if parent_proc in ("powershell.exe", "pwsh.exe"):
recommendation += "\nPowerShell requires additional quoting rules. See " \
"https://github.com/Azure/azure-cli/blob/dev/doc/quoting-issues-with-powershell.md"

# Raise from json_ex error which is more likely to be the original error
raise InvalidArgumentValueError(msg, recommendation=recommendation) from json_ex


def b64encode(s):
Expand Down Expand Up @@ -1222,7 +1236,8 @@ def _get_parent_proc_name():
# Un-cached function to get parent process name.
try:
import psutil
except ImportError:
except ImportError as ex:
logger.debug(ex)
return None

import os
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli-core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

# dependencies for specific OSes
if not sys.platform.startswith('cygwin'):
DEPENDENCIES.append('psutil~=5.7')
DEPENDENCIES.append('psutil~=5.8')
Copy link
Member Author

Choose a reason for hiding this comment

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

Use psutil 5.8 in order to get Python 3.9 support.


TESTS_REQUIRE = [
'mock'
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/requirements.py3.Darwin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ oauthlib==3.0.1
paramiko==2.6.0
pbr==5.3.1
portalocker==1.7.1
psutil==5.7.2
psutil==5.8.0
pycparser==2.19
PyJWT==1.7.1
PyNaCl==1.3.0
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/requirements.py3.Linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ oauthlib==3.0.1
paramiko==2.6.0
pbr==5.3.1
portalocker==1.7.1
psutil==5.7.2
psutil==5.8.0
pycparser==2.19
PyJWT==1.7.1
PyNaCl==1.3.0
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/requirements.py3.windows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ oauthlib==3.0.1
paramiko==2.6.0
pbr==5.3.1
portalocker==1.7.1
psutil==5.7.2
psutil==5.8.0
pycparser==2.19
PyJWT==1.7.1
PyNaCl==1.3.0
Expand Down