{"record":{"id":"4f36b80a3a71b335","repo":"CherryHQ/cherry-studio","slug":"missing-value-for-flag","errorCode":null,"errorMessage":"Missing value for ${flag}","messagePattern":"Missing value for (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/capture-image-response.ts","lineNumber":35,"sourceCode":" * (default POST, or GET when --body is absent), --header (repeatable\n * \"Name: value\"), --out <file> (also write the response there).\n */\nimport { writeFileSync } from 'node:fs'\n\ninterface Args {\n  url?: string\n  body?: string\n  method?: string\n  out?: string\n  headers: Record<string, string>\n}\n\nfunction parseArgs(argv: string[]): Args {\n  const args: Args = { headers: {} }\n  for (let i = 0; i < argv.length; i++) {\n    const flag = argv[i]\n    const value = argv[++i]\n    if (value === undefined) throw new Error(`Missing value for ${flag}`)\n    switch (flag) {\n      case '--url':\n        args.url = value\n        break\n      case '--body':\n        args.body = value\n        break\n      case '--method':\n        args.method = value.toUpperCase()\n        break\n      case '--out':\n        args.out = value\n        break\n      case '--header': {\n        const idx = value.indexOf(':')\n        if (idx === -1) throw new Error(`Invalid --header (expected \"Name: value\"): ${value}`)\n        args.headers[value.slice(0, idx).trim()] = value.slice(idx + 1).trim()\n        break","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/scripts/capture-image-response.ts#L17-L53","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"# before\nnpx tsx scripts/capture-image-response.ts --url\n\n# after\nnpx tsx scripts/capture-image-response.ts --url 'https://api.example.com/v1/images'","handlingStrategy":"validation","validationCode":"// Ensure every flag has a value before invoking the script\nconst required = new Set(['--url'])\nconst tokens = args.join(' ').trim().split(/\\s+/)\nif (tokens.length % 2 !== 0 || required.has(tokens[tokens.length - 1])) {\n  throw new Error('Each flag must be followed by a value')\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["cli","script","args","validation"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}