-
Notifications
You must be signed in to change notification settings - Fork 4
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
Trigger more meaningful validation error messages when trainer registration failed #40
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not obvious to me whether this change is needed because the error has been raised from get_registered_trainer
raise ValueError(f"{trainer_name} is not a registered Trainer.") | ||
raise KeyError(f"{trainer_name} is not a registered Trainer.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be ValueError
. ValueError
suggests the function (get_registered_trainer
) receives an invalid value. https://docs.python.org/3/library/exceptions.html#ValueError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the registry not a key-value mapping? If it's a key-value mapping, I believe KeyError is the more specific, and thus more useful, exception to raise.
except KeyError as e: | ||
raise KeyError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ValueError
, see explanations. I think KeyError
is rarely used and only for a local data type (e.g., a dict, set etc.)
In my tests, the rust-implemented |
Added a test. The test fails before the changes, but succeeds after. Previous test failure output:
|
If a user fails to register their custom
Trainer
class, or they accidentally supply the incorrect trainer type in the trainer config, validation can proceed in a difficult-to-debug manner. This PR introduces more explicit error messages that trigger in this case and can help the user understand the root cause of the issue faster.