{"record":{"id":"7e79aee03baae160","repo":"itwanger/toBeBetterJavaer","slug":"unknown-option-arg","errorCode":null,"errorMessage":"Unknown option: ${arg}","messagePattern":"Unknown option: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/convert-mdnice-images-to-cdn.js","lineNumber":93,"sourceCode":"    } else if (arg.startsWith(\"--domains=\")) {\n      options.domains = parseList(arg.slice(\"--domains=\".length));\n    } else if (arg === \"--prefix\") {\n      options.prefix = requireValue(argv, i);\n      i += 1;\n    } else if (arg.startsWith(\"--prefix=\")) {\n      options.prefix = arg.slice(\"--prefix=\".length);\n    } else if (arg === \"--concurrency\") {\n      options.concurrency = parsePositiveInt(requireValue(argv, i), \"--concurrency\");\n      i += 1;\n    } else if (arg.startsWith(\"--concurrency=\")) {\n      options.concurrency = parsePositiveInt(arg.slice(\"--concurrency=\".length), \"--concurrency\");\n    } else if (arg === \"--limit\") {\n      options.limit = parsePositiveInt(requireValue(argv, i), \"--limit\");\n      i += 1;\n    } else if (arg.startsWith(\"--limit=\")) {\n      options.limit = parsePositiveInt(arg.slice(\"--limit=\".length), \"--limit\");\n    } else if (arg.startsWith(\"-\")) {\n      throw new Error(`Unknown option: ${arg}`);\n    } else {\n      options.targets.push(path.resolve(ROOT_DIR, arg));\n    }\n  }\n\n  if (options.targets.length === 0) {\n    options.targets.push(DEFAULT_TARGET);\n  }\n\n  return options;\n}\n\nfunction requireValue(argv, index) {\n  const value = argv[index + 1];\n  if (!value || value.startsWith(\"-\")) {\n    throw new Error(`Missing value for ${argv[index]}`);\n  }\n  return value;","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/itwanger/toBeBetterJavaer/blob/6617f5fd0b0597735bdc028f2fcd036817877327/scripts/convert-mdnice-images-to-cdn.js#L75-L111","documentation":"Thrown by the argument parser of scripts/convert-mdnice-images-to-cdn.js when a command-line token starts with '-' but does not match any recognized flag (--write, --env, --domains, --prefix, --concurrency, --limit, --verbose, --help/-h). The parser walks argv token by token, and any leading-dash token that falls through every branch hits this guard. It exists to fail fast on typos instead of silently treating the token as a target path.","triggerScenarios":"Running `node scripts/convert-mdnice-images-to-cdn.js --writ` (typo), `--dry-run` (unsupported flag), or `-x`. Also `--limit 5 --dry` where the second unknown flag aborts the run. Note only tokens starting with '-' throw; non-dash tokens are pushed into options.targets as file/dir paths.","commonSituations":"Typoing --verbose/--write; assuming a dry-run flag exists (dry-run is the default without --write); passing an npm script flag without the `--` separator, e.g. `npm run images:cdn --write` instead of `npm run images:cdn -- --write` so npm consumes or mangles it; passing a negative-looking path.","solutions":["Run `node scripts/convert-mdnice-images-to-cdn.js --help` and correct the flag name to one of the supported options","When invoking through npm, use `npm run images:cdn -- <flags>` so flags reach the script","Remember there is no --dry-run flag: omit --write for a dry run"],"exampleFix":"// before\nnode scripts/convert-mdnice-images-to-cdn.js --dry-run --writ\n\n// after (dry run is the default; typo fixed)\nnode scripts/convert-mdnice-images-to-cdn.js --verbose","handlingStrategy":"validation","validationCode":"// Pre-flight: whitelist allowed flags before invoking\nconst ALLOWED = new Set([\"--write\", \"verbose\", \"--env\", \"--domains\", \"--prefix\", \"--concurrency\", \"--limit\", \"--help\", \"-h\"]);\nconst flags = args.filter((a) => a.startsWith(\"-\") && !a.includes(\"=\"));\nconst bad = flags.filter((f) => !ALLOWED.has(f));\nif (bad.length) throw new Error(`Check these flags first: ${bad.join(\", \")}`);","typeGuard":null,"tryCatchPattern":"catch (err) { if (err.message.startsWith(\"Unknown option:\")) { printHelp-ish guidance: run with --help; } else throw err; }","preventionTips":["Keep an npm script wrapper (npm run images:cdn -- <flags>) so flags are typed once","Run with --help after upgrading the script to see the current flag set","Prefer --opt=value forms; typos in them still hit the unknown-option guard instead of misparsing"],"tags":["cli","argument-parsing","usage-error"],"backgroundTag":null,"analyzedSha":"6617f5fd0b0597735bdc028f2fcd036817877327","analyzedAt":"2026-08-14T14:50:55.107Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}