fix(integrations): exit cleanly on malformed --integration-options quoting#3458
fix(integrations): exit cleanly on malformed --integration-options quoting#3458Quratulain-bilal wants to merge 2 commits into
Conversation
…oting
_parse_integration_options called shlex.split(raw_options) unguarded. an
unbalanced quote (e.g. --integration-options='--commands-dir "foo') makes
shlex raise ValueError('No closing quotation'), so a raw traceback escaped
instead of the typer.Exit(1) error every other bad-input path in this function
produces. reachable from specify init and every integration install/switch/
upgrade/migrate that accepts --integration-options.
wrap the split and convert ValueError into the same clean CLI error. added a
regression test; confirmed it fails on the pre-fix code (raw ValueError).
There was a problem hiding this comment.
Pull request overview
Handles malformed integration-option quoting without exposing ValueError tracebacks.
Changes:
- Converts
shlex.splitfailures intotyper.Exit(1). - Adds regression coverage for unbalanced quotes.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/integrations/_helpers.py |
Handles malformed quoting during option parsing. |
tests/integrations/test_integration_subcommand.py |
Tests clean failure on unbalanced quotes. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Medium
| f"[red]Error:[/red] Could not parse integration options " | ||
| f"'{raw_options}': {error}." |
mnriem
left a comment
There was a problem hiding this comment.
Please address Copilot feedback
the malformed-quoting handler (and the unexpected/unknown option branches) interpolate raw_options/token into console.print. a value carrying an unbalanced rich tag like '--commands-dir "[/red]foo' first trips the intended shlex ValueError, but the error print then raises rich.errors.MarkupError and leaks a traceback anyway. escape all three before printing so the clean typer.Exit survives. added a regression covering both the shlex path and a bare markup token.
|
escaped the value before interpolating it in aa810ba — you're right that swept the two sibling branches in the same function too (the 'unexpected option value' and 'unknown option' prints both interpolate the raw token), since a bare regression covers both: an unbalanced-quote value carrying markup, and a plain markup token. confirmed both raise MarkupError on the pre-fix code and exit cleanly with the escape. |
|
Please resolve conflicts |
fixes #3457
_parse_integration_optionscalledshlex.split(raw_options)unguarded. an unbalanced quote in the flag value (e.g.--integration-options='--commands-dir "foo') makes shlex raiseValueError: No closing quotation, so a raw traceback escaped instead of thetyper.Exit(1)error every other bad-input path in this function produces (unknown option, missing value, unexpected value). reachable fromspecify initand every integration install/switch/upgrade/migrate that accepts--integration-options.fix: wrap the
shlex.splitin try/except and convertValueErrorinto the same clean one-line CLI error + exit 1.added a regression test (
test_malformed_quoting_exits_cleanly) asserting atyper.Exiton an unbalanced quote. i confirmed it fails on the pre-fix code by stashing the source and re-running (rawValueError: No closing quotation); the parse-options tests pass with the fix.note: i used an ai assistant to help investigate and write this up.