Skip to content

fix: report a clear error when config has no [requirements] section#100

Open
grische wants to merge 1 commit into
python-morgan:mainfrom
RISEFX:fix/missing-requirements-section
Open

fix: report a clear error when config has no [requirements] section#100
grische wants to merge 1 commit into
python-morgan:mainfrom
RISEFX:fix/missing-requirements-section

Conversation

@grische

@grische grische commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

mirror() crashed with a bare KeyError when the (hand-written) config file was missing the [requirements] section. Raise a ValueError with a message pointing at the config file instead.

@grische
grische requested a review from philnewm July 10, 2026 10:34

@philnewm philnewm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Agreed to have a preflight check for this

@philnewm

Copy link
Copy Markdown
Collaborator

@grische please rebase to ensure the merge conflict gets resolved

mirror() crashed with a bare KeyError when the (hand-written) config
file was missing the [requirements] section. Raise a ValueError with a
message pointing at the config file instead.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@grische
grische force-pushed the fix/missing-requirements-section branch from 448d3a7 to 04add3d Compare July 17, 2026 09:40
@grische
grische requested a review from philnewm July 17, 2026 09:46
@github-actions

Copy link
Copy Markdown

Review

Small, well-targeted fix. mirror() previously crashed with a bare KeyError when morgan.ini had no [requirements] section; this raises a ValueError naming the offending config file instead.

Code quality

  • The fix follows the existing codebase convention exactly (msg = f"..."; raise ValueError(msg), e.g. morgan/__init__.py:570-581), and correctly places the check in the module-level mirror() function rather than in Mirrorer.__init__, since copy_server also constructs a Mirrorer without needing a [requirements] section. Good scoping.

Error handling / UX note (non-blocking)

  • main() doesn't wrap mirror(args) in a try/except (morgan/__init__.py:1001-1002), so the ValueError still propagates as an uncaught exception with a full traceback to the CLI user — same as the adjacent argparse.ArgumentTypeError a few lines above for missing config files. That's consistent with existing behavior, so not a regression, but if the goal is a clean CLI error message (not just a clearer exception type), consider catching config-related ValueErrors in main() and printing them without a traceback. Worth a follow-up if that's the actual pain point, but out of scope for this PR as titled.

Tests

  • New TestMirrorConfigValidation test is well-isolated, reuses the project's established tmp_path/config-writing idiom (matches TestMirrorDependencyErrors at tests/test_init.py:590+), and asserts on the specific error message via pytest.raises(..., match=...). Good coverage for the fix.
  • Minor nit: the test imports the whole morgan module just to call morgan.mirror(args), while the rest of the file imports names directly from morgan (from morgan import (..., Mirrorer, ...)). Could import mirror directly for consistency, though this is trivial.

Documentation

  • No README/CHANGELOG changes — appropriate for a bug-fix-only PR of this size; nothing user-facing to document beyond the improved error message itself.

Security / performance

  • No concerns — this only adds a config validation check with no new I/O, external input handling, or hot-path changes.

Overall: correct, minimal, consistent with project conventions. Approve.

@philnewm

Copy link
Copy Markdown
Collaborator

@grische feel free to decide if this should be included here or not

main() doesn't wrap mirror(args) in a try/except (morgan/init.py:1001-1002), so the ValueError still propagates as an uncaught exception with a full traceback to the CLI user — same as the adjacent argparse.ArgumentTypeError a few lines above for missing config files. That's consistent with existing behavior, so not a regression, but if the goal is a clean CLI error message (not just a clearer exception type), consider catching config-related ValueErrors in main() and printing them without a traceback. Worth a follow-up if that's the actual pain point, but out of scope for this PR as titled.

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