From 0466ebe003cd290d4b3bd72dd64069b715f086a1 Mon Sep 17 00:00:00 2001 From: Larry <554538252@qq.com> Date: Sat, 24 Jun 2023 03:58:25 +0800 Subject: [PATCH] [Core]Fix the error message prompt for command-line parameters in JSON format(--resources) (#36550) Signed-off-by: LarryLian <554538252@qq.com> --- python/ray/_private/utils.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/python/ray/_private/utils.py b/python/ray/_private/utils.py index ac5d35fd56765..0f84ddb33f0b3 100644 --- a/python/ray/_private/utils.py +++ b/python/ray/_private/utils.py @@ -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 @@ -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 @@ -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