-
Notifications
You must be signed in to change notification settings - Fork 6
improve: enhance CV validator error messages with invalid values and valid options #864
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,11 @@ def institution_validator(cls) -> Callable[[CVConfig, 'Request'], None]: | |
| def validate(cv_config: CVConfig, request: 'Request'): | ||
| cv_institution = cv_config.institution(request.metadata.institution_id) | ||
| if cv_institution == 'unknown': | ||
| raise CVEntryError('Unknown "institution_id".') | ||
| valid_institutions = list(cv_config.get_collection('institution_id').keys()) | ||
| raise CVEntryError( | ||
| f'Unknown institution_id "{request.metadata.institution_id}". ' | ||
| f'Valid options: {valid_institutions}' | ||
| ) | ||
|
Comment on lines
+48
to
+51
|
||
| return validate | ||
|
|
||
| @classmethod | ||
|
|
@@ -59,7 +63,11 @@ def model_validator(cls) -> Callable[[CVConfig, 'Request'], None]: | |
| def validate(cv_config: CVConfig, request: 'Request'): | ||
| source = cv_config.source(request.metadata.model_id) | ||
| if source == 'unknown': | ||
| raise CVEntryError('Unknown "model_id".') | ||
| valid_models = list(cv_config.get_collection('source_id').keys()) | ||
| raise CVEntryError( | ||
| f'Unknown model_id "{request.metadata.model_id}". ' | ||
| f'Valid options: {valid_models}' | ||
| ) | ||
| return validate | ||
|
|
||
| @classmethod | ||
|
|
@@ -74,12 +82,20 @@ def experiment_validator(cls) -> Callable[[CVConfig, 'Request'], None]: | |
| def validate(cv_config: CVConfig, request: 'Request'): | ||
| experiment = cv_config.experiment(request.metadata.experiment_id) | ||
| if experiment == 'unknown': | ||
| raise CVEntryError('Unknown experiment_id') | ||
| valid_experiments = list(cv_config.get_collection('experiment_id').keys()) | ||
| raise CVEntryError( | ||
| f'Unknown experiment_id "{request.metadata.experiment_id}". ' | ||
| f'Valid options: {valid_experiments}' | ||
| ) | ||
|
|
||
| if request.metadata.sub_experiment_id != 'none': | ||
| sub_experiment = cv_config.sub_experiment(request.metadata.sub_experiment_id) | ||
| if sub_experiment == 'unknown': | ||
| raise CVEntryError('Sub experiment not conform with CV') | ||
| valid_sub_experiments = list(cv_config.get_collection('sub_experiment_id').keys()) | ||
| raise CVEntryError( | ||
| f'Unknown sub_experiment_id "{request.metadata.sub_experiment_id}". ' | ||
| f'Valid options: {valid_sub_experiments}' | ||
| ) | ||
| return validate | ||
|
|
||
| @classmethod | ||
|
|
@@ -98,13 +114,22 @@ def validate(cv_config: CVConfig, request: 'Request'): | |
|
|
||
| valid_model_types = set(model_types).issubset(set(allowed_model_types)) | ||
| if not valid_model_types: | ||
| raise CVEntryError('Not all model types are allowed by the CV') | ||
| invalid_types = set(model_types) - set(allowed_model_types) | ||
| raise CVEntryError( | ||
| f'Invalid model type(s) {invalid_types}. ' | ||
| f'Allowed types for experiment_id "{request.metadata.experiment_id}": {allowed_model_types}' | ||
| ) | ||
|
Comment on lines
+117
to
+121
|
||
|
|
||
| required_model_types = cv_config.required_source_type(request.metadata.experiment_id) | ||
| if required_model_types: | ||
| contain_required_model_types = set(required_model_types).issubset(set(model_types)) | ||
| if not contain_required_model_types: | ||
| raise CVEntryError('not all required model types are given.') | ||
| missing_types = set(required_model_types) - set(model_types) | ||
| raise CVEntryError( | ||
| f'Missing required model type(s) {missing_types} ' | ||
| f'for experiment_id "{request.metadata.experiment_id}". ' | ||
| f'Provided types: {model_types}' | ||
| ) | ||
|
Comment on lines
+127
to
+132
|
||
| return validate | ||
|
|
||
| @classmethod | ||
|
|
@@ -123,7 +148,13 @@ def validate(cv_config: CVConfig, request: 'Request'): | |
|
|
||
| cv_parent_experiment = cv_config.parent_experiment_id(experiment) | ||
| if cv_parent_experiment == 'unknown': | ||
| raise CVEntryError('Unknown parent experiment id') | ||
| raise CVEntryError( | ||
| f'Unknown parent experiment configuration for experiment_id "{experiment}". ' | ||
| 'Check CV configuration.' | ||
| ) | ||
| if parent_experiment not in cv_parent_experiment: | ||
| raise CVEntryError('Parent experiment id does not match with id in CV config') | ||
| raise CVEntryError( | ||
| f'Invalid parent_experiment_id "{parent_experiment}" for experiment "{experiment}". ' | ||
| f'Valid options: {cv_parent_experiment}' | ||
| ) | ||
| return validate | ||
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.
The error message prints
valid_institutionsusing the rawdict.keys()order and Python list repr. For readability and determinism (and to keep logs/CLI output predictable), consider sorting the options and formatting them as a comma-separated string; if the CV list can be large, consider truncating with a count (e.g., show first N + total).