Missing argument handling
Why it matters
When a required argument is silently missing, the command either crashes mid-execution with a raw TypeError: Cannot read properties of undefined — dumping a stack trace onto the user — or it runs with undefined as a value and produces silent corruption downstream (a deploy target of undefined, a file named undefined.json, a database query with a null key). CWE-233 (Improper Handling of Parameters) applies: the input is invalid, but no validation gate catches it before execution begins. ISO 25010:2011 usability.learnability penalizes CLIs that make users guess what went wrong — the error message must name the missing argument and show the correct usage.
Severity rationale
High because missing required arguments that produce TypeErrors or silent `undefined` behavior give users no actionable path to recovery without reading source code.
Remediation
Use the framework's native required-argument syntax so validation happens before your handler runs. In commander, angle brackets mark required arguments:
program
.command('deploy <target>')
.description('Deploy to the specified target')
.action((target) => {
// commander errors automatically: "error: missing required argument 'target'"
deploy(target)
})
In click, arguments are required by default:
@cli.command()
@click.argument('target') # required — click handles: "Error: Missing argument 'TARGET'."
def deploy(target):
"""Deploy to the specified TARGET."""
pass
Never access argv[n] or opts.target without first confirming the value is defined — opt into your framework's built-in validation rather than writing manual if (!target) guards that are easy to miss.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the CLI Quality Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-233 — Improper Handling of Parameters
- iso-25010:2011 · usability.learnability — Usability — Learnability
Taxons
History
- 2026-04-18·v1.0.0·Initial import from cli-quality·automated