Add config-specific exception hierarchy, validation checks, and CLI validation checks, and CLI error handling#2319
Add config-specific exception hierarchy, validation checks, and CLI validation checks, and CLI error handling#2319
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a configuration-specific exception hierarchy and uses it to fail fast on invalid/missing config file paths, then surfaces these failures as cleaner CLI errors.
Changes:
- Introduce
OumiConfigError/ConfigFileNotFoundErrorand export them fromoumi.core.configs. - Add explicit “path exists and is a file” checks in config loading/saving and in LoRA adapter config discovery/reading (including wrapping read/JSON errors).
- Add unit tests covering the new exception hierarchy and the new validation/error-handling paths.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/core/configs/test_base_config.py | Adds tests for config exception hierarchy and file/path validation behaviors in BaseConfig. |
| tests/unit/core/configs/params/test_model_params.py | Adds tests for adapter config path/file validation and read/JSON error wrapping. |
| src/oumi/core/configs/params/model_params.py | Validates adapter config path is a file; wraps adapter-config read/JSON errors as OumiConfigError. |
| src/oumi/core/configs/exceptions.py | Introduces new config exception types. |
| src/oumi/core/configs/base_config.py | Adds file existence checks and wraps YAML save OSError as OumiConfigError. |
| src/oumi/core/configs/init.py | Re-exports the new config exception types. |
| src/oumi/cli/main.py | Adds a top-level OumiConfigError handler to print a user-friendly error and exit. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
14e626c to
35745d5
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
35745d5 to
9c851f3
Compare
9c851f3 to
e5f549f
Compare
| from oumi.exceptions import ( | ||
| HardwareException, | ||
| OumiConfigError, | ||
| OumiConfigFileNotFoundError, |
There was a problem hiding this comment.
To avoid having too many exceptions we can probably remove OumiConfigFileNotFoundError and just use OumiConfigError
There was a problem hiding this comment.
Removed the separate exception and have tried to simplify code
| OmegaConf.save(config=processed_config, f=config_path) | ||
| except OSError as e: | ||
| # handle missing parent folder | ||
| raise OumiConfigError(f"Failed to save config to {config_path}: {e}") from e |
There was a problem hiding this comment.
I don't think this is a config error -- saving could fail for many reasons. We can check if the parent forlder more explicitely and raise the error then
There was a problem hiding this comment.
Added a directory check and raise hopefully a better error message
| """Base class for all configuration-related errors.""" | ||
|
|
||
|
|
||
| class OumiConfigFileNotFoundError(OumiConfigError, FileNotFoundError): |
There was a problem hiding this comment.
As discussed earlier let's remove this one
There was a problem hiding this comment.
Removed the separate exception
11f1353 to
a2e3d37
Compare
| if not Path(config_path).is_file(): | ||
| raise OumiConfigError( | ||
| f"Config file not found or path is not a file: {config_path}" | ||
| ) |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
@oelachqar what do you think of our above opinion?
AFAIU, you prefer that a permission issue does fully manifest. A configuration mistake is e.g. to point to a folder that does not exist, but any permission issue does not fall under OumiConfigError.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8165f19 to
e46d02e
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Introduce a new lightweight `oumi.exceptions` module with an `OumiConfigError` base class (kept import-cheap for the CLI). - Move `HardwareException` to `oumi.exceptions`. It remains importable from both `oumi.core.types` and `oumi.core.types.exceptions`; the latter is now a thin back-compat shim that re-exports from the canonical location. - Wrap file I/O in `BaseConfig.from_yaml`, the save path, and `_read_config_without_interpolation` to raise `OumiConfigError` on `FileNotFoundError`, `IsADirectoryError`, and `NotADirectoryError` instead of leaking raw OS errors. - Wrap adapter config loading in `ModelParams` to raise `OumiConfigError` on `OSError` and `json.JSONDecodeError`, with file path and parse location in the message. - Handle `OumiConfigError` in the CLI top-level handler so users see a concise red error line and exit code 1 instead of a full traceback. - Update tests accordingly. Fixes OPE-1848
e46d02e to
4804801
Compare
Description
oumi.exceptionsmodule with anOumiConfigErrorbase class (kept import-cheap for the CLI).HardwareExceptiontooumi.exceptions. It remains importablefrom both
oumi.core.typesandoumi.core.types.exceptions; thelatter is now a thin back-compat shim that re-exports from the
canonical location.
BaseConfig.from_yaml, the save path, and_read_config_without_interpolationto raiseOumiConfigErroronFileNotFoundError,IsADirectoryError, andNotADirectoryErrorinstead of leaking raw OS errors.
ModelParamsto raiseOumiConfigErroronOSErrorandjson.JSONDecodeError, withfile path and parse location in the message.
OumiConfigErrorin the CLI top-level handler so users see aconcise red error line and exit code 1 instead of a full traceback.
Related issues
Fixes # (issue)
Before submitting
Reviewers
At least one review from a member of
oumi-ai/oumi-staffis required.