{"record":{"id":"5c639640a7074b8d","repo":"affaan-m/ECC","slug":"missing-value-for-arg","errorCode":null,"errorMessage":"Missing value for ${arg}","messagePattern":"Missing value for (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/codex/check-plugin-cache.js","lineNumber":77,"sourceCode":"    '--version': 'version',\n  };\n  let parsed = {};\n\n  for (let index = 0; index < argv.length; index += 1) {\n    const arg = argv[index];\n    if (arg === '--help' || arg === '-h') {\n      parsed = { ...parsed, help: true };\n      continue;\n    }\n\n    const key = optionKeys[arg];\n    if (!key) {\n      throw new Error(`Unknown argument: ${arg}`);\n    }\n\n    const value = argv[index + 1];\n    if (!value || value.startsWith('--')) {\n      throw new Error(`Missing value for ${arg}`);\n    }\n    index += 1;\n\n    parsed = { ...parsed, [key]: value };\n  }\n\n  const options = { ...defaults, ...parsed };\n  return {\n    ...options,\n    marketplace: validateCacheSegment('--marketplace', options.marketplace),\n    plugin: validateCacheSegment('--plugin', options.plugin),\n    version: validateCacheSegment('--version', options.version),\n    codexHome: path.resolve(options.codexHome),\n    pluginDir: options.pluginDir ? path.resolve(options.pluginDir) : null,\n  };\n}\n\nfunction log(message) {","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/codex/check-plugin-cache.js#L59-L95","documentation":"In check-plugin-cache.js parseArgs(), after matching a known flag, the parser reads argv[index + 1] as its value. If that value is undefined (flag is last) or starts with '--' (looks like another flag), it throws. This prevents the parser from silently consuming a flag name as a value for the preceding flag.","triggerScenarios":"Passing --codex-home as the last argument with no value; passing --marketplace immediately followed by another flag like --plugin; or a copy-paste error that drops the intended value.","commonSituations":"Dynamic CLI construction in CI that conditionally appends a flag without its value; scripts that pass flags based on optional environment variables that are unset.","solutions":["Provide a concrete value immediately after each flag, e.g. --codex-home ~/.codex","If building commands dynamically, verify the value variable is truthy before appending both the flag and its value","Run with --help to confirm which flags expect values"],"exampleFix":"// before\nnode scripts/codex/check-plugin-cache.js --codex-home --plugin ecc\n// after\nnode scripts/codex/check-plugin-cache.js --codex-home ~/.codex --plugin ecc","handlingStrategy":"validation","validationCode":"// Verify each value-expecting flag has a companion value\nconst FLAGS_REQUIRING_VALUE = new Set(['--codex-home', '--plugin-dir', '--marketplace', '--plugin', '--version']);\nconst argv = process.argv.slice(2);\nfor (let i = 0; i < argv.length; i++) {\n  if (FLAGS_REQUIRING_VALUE.has(argv[i])) {\n    if (!argv[i + 1] || argv[i + 1].startsWith('--')) {\n      console.error(`Missing value for ${argv[i]}`);\n      process.exit(1);\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  const options = parseArgs(process.argv.slice(2));\n} catch (error) {\n  if (error.message.startsWith('Missing value for')) {\n    console.error(error.message);\n    console.error('Each flag above requires a value as the next argument.');\n    usage();\n    process.exit(2);\n  }\n  throw error;\n}","preventionTips":["Place the value immediately after each flag with no gap","When building commands from variables, check truthiness before appending both flag and value","Avoid placing two value-expecting flags adjacent without their values"],"tags":["cli","argument-parsing","codex"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}