Skip to content

Commit

Permalink
[Core]Fix the error message prompt for command-line parameters in JSO…
Browse files Browse the repository at this point in the history
…N format(--resources) (#36550)

Signed-off-by: LarryLian <554538252@qq.com>
  • Loading branch information
larrylian authored Jun 23, 2023
1 parent 8480709 commit 0466ebe
Showing 1 changed file with 18 additions and 10 deletions.
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

0 comments on commit 0466ebe

Please sign in to comment.