From c43b1c015b597db6c09c38cda59c81156042d111 Mon Sep 17 00:00:00 2001 From: Dimitris Papagiannis Date: Wed, 23 Oct 2024 10:47:58 +0200 Subject: [PATCH] Raise ValueError where appropriate Invalid inputs usually raise a ValueError, AFAIK. Generic Exceptions are kept for permission errors. TODO: Maybe create a custom Exception for the latter case. --- runregistry/runregistry.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runregistry/runregistry.py b/runregistry/runregistry.py index 5c2f837..4a387b1 100644 --- a/runregistry/runregistry.py +++ b/runregistry/runregistry.py @@ -615,7 +615,7 @@ def _execute_request_for_single_run(run_number, new_class): ) if not isinstance(new_class, str): - raise Exception(f'Invalid input "{new_class}" for "new_class"') + raise ValueError(f'Invalid input "{new_class}" for "new_class"') answers = [] # If just one int provided, make it into a list if isinstance(run_numbers, int): @@ -624,7 +624,7 @@ def _execute_request_for_single_run(run_number, new_class): if isinstance(run_numbers, list): for run_number in run_numbers: if not isinstance(run_number, int): - raise Exception( + raise ValueError( "Invalid run number value found in run_numbers. Please provide a list of numbers." ) answer = _execute_request_for_single_run(run_number, new_class) @@ -634,7 +634,7 @@ def _execute_request_for_single_run(run_number, new_class): ) answers.append(answer.json()) else: - raise Exception( + raise ValueError( 'Invalid input for "run_numbers". Please provide a list of numbers.' ) return answers