agencyenterprise / neural-data-simulator

Electrophysiology data simulator for developing brain-computer interfaces
https://agencyenterprise.github.io/neural-data-simulator/
Apache License 2.0
71 stars 7 forks source link

Show the invalid value during `pydantic.error_wrappers.ValidationError` #58

Open charlesbmi opened 1 year ago

charlesbmi commented 1 year ago

Prerequisite: https://github.com/agencyenterprise/neural-data-simulator/issues/48

Describe the new feature or enhancement

Please provide a clear and concise description of what you want to add or change. When an NDS user passes in an invalid argument (via settings.yaml or the command-line), NDS surfaces an error like:

pydantic.error_wrappers.ValidationError: 1 validation error for _Settings
log_level
  value is not a valid enumeration member; permitted: 'DEBUG', 'INFO', 'ERROR', 'WARNING', 'CRITICAL' (type=type_error.enum; enum_values=[<LogLevel._DEBUG: 'DEBUG'>, <LogLevel._INFO: 'INFO'>, <LogLevel._ERROR: 'ERROR'>, <LogLevel._WARNING: 'WARNING'>, <LogLevel._CRITICAL: 'CRITICAL'>])

It indicates the field name and valid values, but not the passed-in invalid value. It would be helpful to also print the invalid value (or an abbreviated version of it).

Please describe how you would use this new feature. This is particularly helpful for fixing command-line arguments, where it's not obvious how the run_*.py scripts parse the input arguments without looking at the source code.

Describe your proposed implementation

Describe how you think the feature or improvement should be implemented. Use the input_value field of ValidationError, which is new in PyDantic V2.

Describe possible alternatives

If you've suggested an implementation above, list here any alternative implementations you can think of, and brief comments explaining why the chosen implementation is better.