Skip to content

feat(config): add validation for config file paths and improve error … - #1044

Open
wakonig wants to merge 4 commits into
mainfrom
feature/config_load_error
Open

feat(config): add validation for config file paths and improve error …#1044
wakonig wants to merge 4 commits into
mainfrom
feature/config_load_error

Conversation

@wakonig

@wakonig wakonig commented Sep 8, 2026

Copy link
Copy Markdown
Member

Description

A typo while loading the config can lead to a confusing "NotImplementedError" as the system first checks against the suffix. This PR changes the config loading by verifying that file exists before checking for compatibility. Moreover, it tries to give a more helpful error message by checking yaml and yml files that the user may have wanted to use instead.

Potential side effects

I decided to not automatically load the found config as this could be quite nasty to debug and lead to unexpected results.

Screenshots / GIFs (if applicable)

Examples:

bec.config.update_session_with_file("./bec_lib/bec_lib/tests/test_confi")
>>> DeviceConfigError: Config file 'bec_lib/bec_lib/tests/test_confi' does not exist.

bec.config.update_session_with_file("./bec_lib/bec_lib/tests/test_config")
>>> DeviceConfigError: Config file 'bec_lib/bec_lib/tests/test_config' does not exist. Did you mean 'bec_lib/bec_lib/tests/test_config.yaml'?

bec.config.update_session_with_file("./bec_lib/bec_lib/tests/test_config.yml")
>>> DeviceConfigError: Config file 'bec_lib/bec_lib/tests/test_config.yml' does not exist. Did you mean 'bec_lib/bec_lib/tests/test_config.yaml'?

bec.config.update_session_with_file("./bec_lib/bec_lib/tests/test_confg.yaml")
>>> DeviceConfigError: Config file 'bec_lib/bec_lib/tests/test_confg.yaml' does not exist. Did you mean 'bec_lib/bec_lib/tests/test_config.yaml'?

@wakonig wakonig self-assigned this Sep 8, 2026
@wakonig
wakonig force-pushed the feature/config_load_error branch from bfc4342 to 579709a Compare September 8, 2026 17:27
@wakonig
wakonig marked this pull request as ready for review September 8, 2026 17:31
Copilot AI lite review requested due to automatic review settings September 8, 2026 17:31

Copilot AI left a comment

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.

🟡 Changes recommended

The new path validation does not ensure the path is a regular file, so a directory named *.yaml/*.yml can slip through and later fail with an unexpected IsADirectoryError instead of a DeviceConfigError.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR improves bec_lib configuration loading error handling by validating config file paths before checking YAML compatibility, and by suggesting likely .yaml/.yml alternatives when the provided path is missing—avoiding the previously confusing NotImplementedError behavior.

Changes:

  • Add explicit config-path validation that raises DeviceConfigError with clearer messages (and optional “Did you mean …?” suggestions).
  • Add comprehensive unit tests covering unsupported extensions, missing files, suggestion ordering/limits, and error-tolerant directory scanning.
File summaries
File Description
bec_lib/bec_lib/config_helper.py Adds path validation + alternative suggestion logic for missing config files.
bec_lib/tests/test_config_helper.py Adds/extends tests for missing/unsupported config path handling and suggestion behavior.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread bec_lib/bec_lib/config_helper.py Outdated
@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@wakonig
wakonig force-pushed the feature/config_load_error branch from 579709a to fee69fd Compare September 8, 2026 18:08

Copilot AI left a comment

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.

🟢 Approval recommended

The changes are coherent, well-tested, and align with the PR’s stated goal of improving config-loading validation and error reporting without introducing breaking cross-service contract changes.

Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@wakonig
wakonig requested a review from a team September 9, 2026 07:21
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.

2 participants