Skip to content

fix(cli): handle TOML syntax errors gracefully#221

Merged
tomschr merged 4 commits intoopenSUSE:mainfrom
sushant-suse:issue#175
Apr 22, 2026
Merged

fix(cli): handle TOML syntax errors gracefully#221
tomschr merged 4 commits intoopenSUSE:mainfrom
sushant-suse:issue#175

Conversation

@sushant-suse
Copy link
Copy Markdown
Collaborator

Changes

Core Logic & CLI

  • src/docbuild/cli/cmd_cli.py:
    • Wrapped the handle_config calls for both Application and Environment configurations in try...except blocks to catch tomllib.TOMLDecodeError.
    • Updated handle_validation_error (and its internal logic) to distinguish between TOML syntax errors and Pydantic validation errors.
    • Ensured the specific filename causing the syntax error is passed to the error formatter to provide better context.
    • Initialized configuration dictionaries to prevent Pylance "possibly unbound" warnings.

Utilities

  • src/docbuild/utils/errors.py:
    • Added a new format_toml_error function. This uses the rich library to print a clean, red-styled error panel.
    • The panel includes the specific error message from the parser (including line/column) and a helpful hint about TOML boolean casing.

Tests

  • tests/utils/test_errors.py: Added a test to verify that the format_toml_error utility correctly captures and formats a syntax error.
  • tests/cli/test_cmd_cli.py: Added an end-to-end test that mocks a TOMLDecodeError during the CLI initialization to verify the program exits with code 1 and displays the correct error message without a traceback.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 21, 2026

Coverage Report

For commit 54bc798

Click to expand Coverage Report
  Name                                           Stmts   Miss Branch BrPart  Cover
  --------------------------------------------------------------------------------
+ src/docbuild/models/deliverable.py               180      1     22      0  99.5%
+ src/docbuild/cli/cmd_check/process.py             58      0     22      1  98.8%
+ src/docbuild/models/manifest.py                  111      1     12      1  98.4%
+ src/docbuild/utils/pidlock.py                     79      1     14      1  97.8%
+ src/docbuild/cli/cmd_cli.py                      106      1     12      2  97.5%
+ src/docbuild/cli/cmd_validate/process.py         178      5     52      4  96.1%
+ src/docbuild/cli/callback.py                      35      0     10      2  95.6%
+ src/docbuild/utils/concurrency.py                 69      3     18      1  95.4%
- src/docbuild/cli/cmd_config/__init__.py            9      1      0      0  88.9%
- src/docbuild/config/xml/stitch.py                 47      5     12      0  88.1%
- src/docbuild/cli/cmd_metadata/metaprocess.py     215     26     66     13  82.6%
- src/docbuild/cli/cmd_check/__init__.py            18      5      2      0  65.0%
- src/docbuild/cli/cmd_build/__init__.py            13      5      0      0  61.5%
- src/docbuild/cli/cmd_metadata/__init__.py         27     10      2      0  58.6%
- src/docbuild/cli/cmd_config/environment.py        11      6      2      0  38.5%
  --------------------------------------------------------------------------------
+ TOTAL                                           3011     70    708     25  97.0%
  
  46 files skipped due to complete coverage.

@sushant-suse sushant-suse requested a review from tomschr April 21, 2026 08:03
Copy link
Copy Markdown
Contributor

@tomschr tomschr left a comment

Choose a reason for hiding this comment

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

Thanks @sushant-suse for the work. 👍 It took a bit longer for me.

Overall it looks good. 👍 Apart from minor details, I have some concerns regarding an anti pattern (see below). Not sure if we want to fix it here in this PR as it deviates from the original issue.

Comment thread src/docbuild/cli/cmd_cli.py Outdated
Comment thread src/docbuild/cli/cmd_cli.py Outdated
Comment thread src/docbuild/utils/errors.py
@sushant-suse sushant-suse requested a review from tomschr April 21, 2026 15:47
Copy link
Copy Markdown
Contributor

@tomschr tomschr left a comment

Choose a reason for hiding this comment

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

Just a tiny addition, otherwise it's great. 👍 Thank you! I think, it's ready to be squash-merged to main.

Comment thread src/docbuild/cli/cmd_cli.py Outdated
Comment thread src/docbuild/cli/cmd_cli.py Outdated
@sushant-suse
Copy link
Copy Markdown
Collaborator Author

Just a tiny addition, otherwise it's great. 👍 Thank you! I think, it's ready to be squash-merged to main.

Also forgot to add fragment file. Added that as well.

@sushant-suse sushant-suse requested a review from tomschr April 22, 2026 09:07
Copy link
Copy Markdown
Contributor

@tomschr tomschr left a comment

Choose a reason for hiding this comment

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

Thanks! 👍

@tomschr tomschr merged commit 2309ed5 into openSUSE:main Apr 22, 2026
9 checks passed
@sushant-suse sushant-suse deleted the issue#175 branch April 23, 2026 07:13
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