Skip to content

fix(cli): reject missing option values instead of crashing under set -u - #6178

Open
0xacee wants to merge 1 commit into
Osmantic:public-betafrom
0xacee:fix/missing-option-arg
Open

0xacee wants to merge 1 commit into
Osmantic:public-betafrom
0xacee:fix/missing-option-arg

Conversation

@0xacee

@0xacee 0xacee commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Every ODS entry-point script runs under set -euo pipefail, but 13 option parsers read "$2" without checking it exists. Passing a documented value-option as the last argument crashes with $2: unbound variable — no usage hint, and in install-core.sh's case the ERR trap prints a misleading "Installation failed during phase: init" banner for what is really a CLI typo.

Why this matters

All of these are documented in each script's --help output, so ./install.sh --tier (forgot the tier), ods backup --output (forgot the path), ods-test.sh -s (forgot the service) are reachable operator errors. The crash also bypasses each script's own error convention (error(), log_error+usage, exit-code contract), which matters for wrappers and CI that parse stderr.

Sites fixed (guard convention copied from ods-uninstall.sh, which already has it):

  • install-core.sh — --tier, --lemonade-url, --lemonade-api-key, --external-llm-url, --external-llm-provider, --external-llm-model, --summary-json
  • ods-backup.sh — -o|--output, -t|--type, -d|--delete, --description
  • scripts/pre-download.sh — --tier
  • scripts/ods-test.sh — -s|--service

Each arm now does [[ $# -ge 2 && -n "$2" ]] || <file's error path> before consuming $2, rejecting both a missing argument and an explicitly empty one.

Overlap check

Regression test

ods/tests/test-option-arg-guards.sh runs all 17 flag spellings as trailing arguments and asserts: non-zero exit, no unbound variable text, and a requires-style error message.

Validation

  • Fix branch: 17 passed, 0 failed.
  • Clean upstream/public-beta (4d725ee95): 0 passed, 17 failed — every site crashes on unbound variable.
  • bash -n and shellcheck -S error clean on all 5 files; git diff --check clean.

Pending: CI and maintainer review.

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.

1 participant