Skip to content

fix: malformed -ks/-kb/-kf/-kg arguments caused tracebacks - #16

Merged
paulmueller merged 1 commit into
DC-analysis:mainfrom
paulmueller-agent:fix-cli-kwargs
Nov 23, 2026
Merged

paulmueller merged 1 commit into
DC-analysis:mainfrom
paulmueller-agent:fix-cli-kwargs

Conversation

@paulmueller-agent

Copy link
Copy Markdown

Bug

The -ks/-kb/-kf/-kg KEY=VALUE arguments were split with a.split("=") and converted without error handling, so mistakes ended in raw tracebacks:

$ chipstream-cli --dry-run -ks thresh data.rtdc
ValueError: not enough values to unpack (expected 2, got 1)
$ chipstream-cli --dry-run -ks thresh=1=2 data.rtdc
ValueError: too many values to unpack (expected 2)
$ chipstream-cli --dry-run -ks foo=1 data.rtdc
ValueError: Invalid keyword 'foo' for thresh. Allowed keywords are [...]!   (as a traceback)
$ chipstream-cli --dry-run -kg size_thresh_mask=None data.rtdc
ValueError: invalid literal for int() with base 10: 'None'
$ chipstream-cli --dry-run -kb kernel_size=abc data.rtdc
ValueError: invalid literal for int() with base 10: 'abc'
  • Values containing = (e.g. a model file path for -ks model_file=...) could not be passed.
  • size_thresh_mask=None is listed as the default in --help, but None was not accepted.

Fix

In chipstream/cli/cli_valid.py:

  • split_kwargs splits on the first = only and raises click.BadParameter for arguments without = or without a key.
  • convert_kwarg_value converts None/none to None if the annotation allows None, and turns conversion errors into click.BadParameter.
  • Unknown keywords raise click.BadParameter instead of ValueError.
  • Missing annotations default to str (as the existing comment says) instead of raising KeyError.

The CLI now prints a usage error and exits with 2:

Error: Invalid value for '-ks': Expected 'KEY=VALUE', got 'thresh'
Error: Invalid value for '-ks': Invalid value '1=2' for keyword 'thresh' (expected float): could not convert string to float: '1=2'
Error: Invalid value for '-ks': Invalid keyword 'foo' for 'thresh'. Allowed keywords are ['thresh', 'clear_border', 'fill_holes', 'closing_disk']!
Error: Invalid value for '-kb': Invalid value 'abc' for keyword 'kernel_size' (expected int): invalid literal for int() with base 10: 'abc'

-kg size_thresh_mask=None now gives the same gate ID and pipeline hash as omitting it.

Tests

  • test_cli_kwargs_invalid (11 cases across -ks/-kb/-kf/-kg): exit code 2 and the message.
  • test_cli_kwargs_none: None, none and 10 for size_thresh_mask.
  • test_cli_kwargs_split_first_equal_sign and test_cli_kwargs_value_with_equal_sign (torch only): values containing =.

All new tests fail on main and pass with the fix. test_cli_torchmpo and test_cli_torchmpo_wrong_model still pass. flake8 is clean; ruff shows no new errors.

🤖 Generated with Claude Code

- split `KEY=VALUE` on the first "=" only, so values (e.g. model file
  paths) may contain "="
- raise `click.BadParameter` for arguments without "=" or key, unknown
  keys, and values that cannot be converted to the annotated type
- accept "None" for keyword arguments that allow `None` (e.g. the
  default `size_thresh_mask=None` listed in the help)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.00%. Comparing base (e5709a5) to head (dbee697).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #16      +/-   ##
==========================================
+ Coverage   74.73%   76.00%   +1.26%     
==========================================
  Files          19       19              
  Lines        1330     1350      +20     
==========================================
+ Hits          994     1026      +32     
+ Misses        336      324      -12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@paulmueller
paulmueller merged commit a5069ff into DC-analysis:main Nov 23, 2026
8 checks passed
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