Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core]Fix the error message prompt for command-line parameters in JSON format(--resources) #36550

Merged
merged 1 commit into from
Jun 23, 2023
Merged
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
28 changes: 18 additions & 10 deletions python/ray/_private/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,13 +1421,17 @@ def parse_resources_json(
try:
resources = json.loads(resources)
if not isinstance(resources, dict):
raise ValueError
except Exception:
cli_logger.error("`{}` is not a valid JSON string.", cf.bold(command_arg))
raise ValueError("The format after deserialization is not a dict")
except Exception as e:
cli_logger.error(
"`{}` is not a valid JSON string, detail error:{}",
cf.bold(f"{command_arg}={resources}"),
str(e),
)
cli_logger.abort(
"Valid values look like this: `{}`",
cf.bold(
f'{command_arg}=\'{{"CustomResource3": 1, ' '"CustomResource2": 2}}\''
f'{command_arg}=\'{{"CustomResource3": 1, "CustomResource2": 2}}\''
),
)
return resources
Expand All @@ -1439,12 +1443,16 @@ def parse_metadata_json(
try:
metadata = json.loads(metadata)
if not isinstance(metadata, dict):
raise ValueError
except Exception:
cli_logger.error("`{}` is not a valid JSON string.", cf.bold(command_arg))
raise ValueError("The format after deserialization is not a dict")
except Exception as e:
cli_logger.error(
"`{}` is not a valid JSON string, detail error:{}",
cf.bold(f"{command_arg}={metadata}"),
str(e),
)
cli_logger.abort(
"Valid values look like this: `{}`",
cf.bold(f'{command_arg}=\'{{"key1": "value1", ' '"key2": "value2"}}\''),
cf.bold(f'{command_arg}=\'{{"key1": "value1", "key2": "value2"}}\''),
)
return metadata

Expand Down Expand Up @@ -1925,11 +1933,11 @@ def parse_node_labels_json(
except Exception as e:
cli_logger.error(
"`{}` is not a valid JSON string, detail error:{}",
cf.bold(command_arg),
cf.bold(f"{command_arg}={labels_json}"),
str(e),
)
cli_logger.abort(
"Valid values look like this: `{}`",
cf.bold(f'{command_arg}=\'{{"gpu_type": "A100", ' '"region": "us"}}\''),
cf.bold(f'{command_arg}=\'{{"gpu_type": "A100", "region": "us"}}\''),
)
return labels