From bfba6d037c30fa3045d4d445ec7502af7219edae Mon Sep 17 00:00:00 2001 From: jbleon95 Date: Tue, 1 Oct 2024 13:40:00 -0400 Subject: [PATCH] catch specific errors and raise click BadParameter --- api/src/opentrons/cli/analyze.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/api/src/opentrons/cli/analyze.py b/api/src/opentrons/cli/analyze.py index d86f17427de..f311adce402 100644 --- a/api/src/opentrons/cli/analyze.py +++ b/api/src/opentrons/cli/analyze.py @@ -220,12 +220,16 @@ def _get_runtime_parameter_values( rtp_values = {} try: for variable_name, value in json.loads(serialized_rtp_values).items(): - assert isinstance( - value, (bool, int, float, str) - ), f"Value '{value}' is not of allowed type boolean, integer, float or string" + if not isinstance(value, (bool, int, float, str)): + raise click.BadParameter( + f"Runtime parameter '{value}' is not of allowed type boolean, integer, float or string", + param_hint="--rtp-values", + ) rtp_values[variable_name] = value - except Exception as error: - raise click.ClickException(f"Could not parse runtime parameter values: {error}") + except json.JSONDecodeError as error: + raise click.BadParameter( + f"JSON decode error: {error}", param_hint="--rtp-values" + ) return rtp_values @@ -235,8 +239,10 @@ def _get_runtime_parameter_paths(serialized_rtp_files: str) -> CSVRuntimeParamPa variable_name: Path(path_string) for variable_name, path_string in json.loads(serialized_rtp_files).items() } - except Exception as error: - raise click.ClickException(f"Could not parse runtime parameter files: {error}") + except json.JSONDecodeError as error: + raise click.BadParameter( + f"JSON decode error: {error}", param_hint="--rtp-files" + ) R = TypeVar("R")