CherryHQ/cherry-studio · error · Error
Missing value for ${flag}
Error message
Missing value for ${flag} What it means
Thrown by the argument parser in scripts/capture-image-response.ts when a CLI flag is the last token on the command line with no value following it. The parser pairs each flag (--url, --body, --method, --out, --header) with the next argv entry; if there is no next entry (undefined), the flag is missing its required value.
Source
Thrown at scripts/capture-image-response.ts:35
* (default POST, or GET when --body is absent), --header (repeatable
* "Name: value"), --out <file> (also write the response there).
*/
import { writeFileSync } from 'node:fs'
interface Args {
url?: string
body?: string
method?: string
out?: string
headers: Record<string, string>
}
function parseArgs(argv: string[]): Args {
const args: Args = { headers: {} }
for (let i = 0; i < argv.length; i++) {
const flag = argv[i]
const value = argv[++i]
if (value === undefined) throw new Error(`Missing value for ${flag}`)
switch (flag) {
case '--url':
args.url = value
break
case '--body':
args.body = value
break
case '--method':
args.method = value.toUpperCase()
break
case '--out':
args.out = value
break
case '--header': {
const idx = value.indexOf(':')
if (idx === -1) throw new Error(`Invalid --header (expected "Name: value"): ${value}`)
args.headers[value.slice(0, idx).trim()] = value.slice(idx + 1).trim()
breakView on GitHub (pinned to 726446b54c)
Solutions
- Supply a value after every flag: npx tsx scripts/capture-image-response.ts --url 'https://...' --header "Authorization: Bearer $KEY".
- If a value comes from an env var, default it in the shell first (URL="${URL:?required}") so an empty var fails loudly before the script runs.
- Check for stray trailing flags or copy-paste truncation in the command line.
- Quote each argument so the shell cannot elide empty values.
Example fix
# before npx tsx scripts/capture-image-response.ts --url # after npx tsx scripts/capture-image-response.ts --url 'https://api.example.com/v1/images'
Defensive patterns
Strategy: validation
Validate before calling
// Ensure every flag has a value before invoking the script
const required = new Set(['--url'])
const tokens = args.join(' ').trim().split(/\s+/)
if (tokens.length % 2 !== 0 || required.has(tokens[tokens.length - 1])) {
throw new Error('Each flag must be followed by a value')
} Prevention
- Always pair a flag with its value on the command line.
- Default env-derived values in the shell first (VAR="${VAR:?required}") so empty vars fail early.
- Quote arguments to prevent the shell from eliding empty values.
When it happens
Trigger: Invoking the script with a trailing flag that has no argument, e.g. npx tsx scripts/capture-image-response.ts --url (nothing after --url), or --header as the last token. Also when a shell quoting error drops the value (e.g. an unquoted empty string that the shell elided).
Common situations: Typing the command manually and forgetting the value; a copy-paste that truncated the line; shell expansion of an unset env var (e.g. --header "Authorization: Bearer $MISSING") producing an empty/missing token; CI script assembling the command from variables where one is empty.
Related errors
- Invalid --header (expected "Name: value"): ${value}
- Unknown flag: ${flag}
- Private key must be a non-empty string
- Invalid PEM format: missing BEGIN/END markers or key content
- Private key content is empty after cleaning
AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12).
Data as JSON: /api/errors/4f36b80a3a71b335.
Report an issue: GitHub.