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.
| if not Path(config_path).is_file(): | ||
| raise ConfigFileNotFoundError( | ||
| f"Config file not found or path is not a file: {config_path}" | ||
| ) | ||
| with open(config_path) as f: | ||
| stringified_config = f.read() |
There was a problem hiding this comment.
_read_config_without_interpolation() now checks is_file() but still calls open() without handling permission/IO errors. If the file exists but is unreadable (e.g., permission denied), this will raise a raw OSError and bypass the new OumiConfigError/CLI-friendly path. Consider catching OSError around the file read and re-raising as OumiConfigError with the path included (while preserving the original exception via from).
| return app() | ||
| except OumiConfigError as e: | ||
| logging.getLogger(__name__).debug(traceback.format_exc()) | ||
| CONSOLE.print(f"[red]Error: {e}[/red]") |
There was a problem hiding this comment.
CONSOLE.print(f"[red]Error: {e}[/red]") uses Rich markup interpolation with an exception message that may contain [/] or other markup-like sequences. That can lead to malformed markup and potentially raise during error handling, hiding the original config error. Prefer printing with style="red" (or escaping the message) so exception text is treated as plain text.
| CONSOLE.print(f"[red]Error: {e}[/red]") | |
| CONSOLE.print(f"Error: {e}", style="red") |
| except OumiConfigError as e: | ||
| logging.getLogger(__name__).debug(traceback.format_exc()) | ||
| CONSOLE.print(f"[red]Error: {e}[/red]") | ||
| sys.exit(1) | ||
| except Exception as e: |
There was a problem hiding this comment.
The new top-level CLI handler only treats OumiConfigError as a user-facing configuration error, but most config validation in this repo raises ValueError (e.g., in ModelParams and many other config/params classes). As a result, many invalid-config cases will still fall into the generic except Exception branch and print a full traceback. If the intent is consistent user-friendly config errors, consider also handling ValueError (or normalizing validation errors to OumiConfigError).
There was a problem hiding this comment.
This will be handled in a separate PR
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.
| Returns: | ||
| BaseConfig: The merged configuration object. | ||
| """ | ||
| if not Path(config_path).is_file(): |
There was a problem hiding this comment.
from_yaml() now checks Path(config_path).is_file() and then (in the default ignore_interpolation=True path) calls _read_config_without_interpolation(), which performs the same is_file() check again. Consider centralizing the check (e.g., rely on _read_config_without_interpolation for that branch, or factor out a shared helper) to avoid redundant filesystem stats and duplicated error logic.
| if not Path(config_path).is_file(): | |
| if not ignore_interpolation and not Path(config_path).is_file(): |
| return app() | ||
| except OumiConfigError as e: | ||
| logging.getLogger(__name__).debug(traceback.format_exc()) | ||
| CONSOLE.print(f"[red]Error: {e}[/red]") |
There was a problem hiding this comment.
CLI error formatting here differs from the pattern used elsewhere in the CLI ([red]Error:[/red] ... in e.g. cli/analyze.py and cli/deploy.py). For consistency, consider using the same [red]Error:[/red] {e} formatting (and keep only the “Error:” prefix styled).
| CONSOLE.print(f"[red]Error: {e}[/red]") | |
| CONSOLE.print(f"[red]Error:[/red] {e}") |
35745d5 to
9c851f3
Compare
…rror handling Introduce dedicated config exception types and add explicit configuration checks to catch invalid or missing values early. Wire these failures into the CLI global handler so users get clearer, consistent error messages. Improve current file checks during configuration parsing. Fixes OPE-1848
9c851f3 to
e5f549f
Compare
Description
Introduce dedicated config exception types and add explicit configuration checks to catch invalid or missing values early. Wire these failures into the CLI global handler so users get clearer, consistent error messages. Improve current file checks during configuration parsing
Related issues
Fixes # (issue)
Before submitting
Reviewers
At least one review from a member of
oumi-ai/oumi-staffis required.