Skip to content

Add config-specific exception hierarchy, validation checks, and CLI validation checks, and CLI error handling#2319

Open
idoudali wants to merge 1 commit intomainfrom
idoudali/config-exceptions
Open

Add config-specific exception hierarchy, validation checks, and CLI validation checks, and CLI error handling#2319
idoudali wants to merge 1 commit intomainfrom
idoudali/config-exceptions

Conversation

@idoudali
Copy link
Copy Markdown
Contributor

@idoudali idoudali commented Mar 26, 2026

Description

  • 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.

Related issues

Fixes # (issue)

Before submitting

  • This PR only changes documentation. (You can ignore the following checks in that case)
  • Did you read the contributor guideline Pull Request guidelines?
  • Did you link the issue(s) related to this PR in the section above?
  • Did you add / update tests where needed?

Reviewers

At least one review from a member of oumi-ai/oumi-staff is required.

@idoudali idoudali requested a review from oelachqar March 26, 2026 12:06
@idoudali idoudali self-assigned this Mar 26, 2026
Copilot AI review requested due to automatic review settings March 26, 2026 12:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / ConfigFileNotFoundError and export them from oumi.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.

Comment thread src/oumi/core/configs/base_config.py Outdated
Comment thread src/oumi/cli/main.py Outdated
Comment thread src/oumi/cli/main.py
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/oumi/core/configs/base_config.py Outdated
Comment thread src/oumi/cli/main.py Outdated
Comment thread src/oumi/core/configs/exceptions.py Outdated
from oumi.exceptions import (
HardwareException,
OumiConfigError,
OumiConfigFileNotFoundError,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid having too many exceptions we can probably remove OumiConfigFileNotFoundError and just use OumiConfigError

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the separate exception and have tried to simplify code

Comment thread src/oumi/core/configs/base_config.py Outdated
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a directory check and raise hopefully a better error message

Comment thread src/oumi/exceptions.py Outdated
"""Base class for all configuration-related errors."""


class OumiConfigFileNotFoundError(OumiConfigError, FileNotFoundError):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed earlier let's remove this one

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the separate exception

@gitar-bot
Copy link
Copy Markdown

gitar-bot bot commented Apr 14, 2026

Gitar is working

Gitar

@idoudali idoudali force-pushed the idoudali/config-exceptions branch from 11f1353 to a2e3d37 Compare April 16, 2026 22:10
Comment thread src/oumi/core/configs/base_config.py Outdated
Comment on lines +202 to +205
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/oumi/core/configs/base_config.py Outdated
Comment thread src/oumi/core/configs/base_config.py Outdated
Comment thread src/oumi/core/configs/params/model_params.py Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/oumi/core/types/__init__.py
- 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
@idoudali idoudali force-pushed the idoudali/config-exceptions branch from e46d02e to 4804801 Compare April 17, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants