{"record":{"id":"12ff8ba4bbce93b3","repo":"itwanger/toBeBetterJavaer","slug":"unknown-option-arg-12ff8b","errorCode":null,"errorMessage":"Unknown option: ${arg}","messagePattern":"Unknown option: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/sync-sidebar.js","lineNumber":81,"sourceCode":"    } else if (arg.startsWith(\"--sidebar=\")) {\n      options.sidebar = path.resolve(ROOT_DIR, arg.slice(\"--sidebar=\".length));\n    } else if (arg === \"--route\") {\n      options.route = normalizeRoute(requireValue(argv, index));\n      index += 1;\n    } else if (arg.startsWith(\"--route=\")) {\n      options.route = normalizeRoute(arg.slice(\"--route=\".length));\n    } else if (arg === \"--dir\") {\n      options.dir = requireValue(argv, index);\n      index += 1;\n    } else if (arg.startsWith(\"--dir=\")) {\n      options.dir = arg.slice(\"--dir=\".length);\n    } else if (arg === \"--fallback\") {\n      options.fallbackGroup = requireValue(argv, index);\n      index += 1;\n    } else if (arg.startsWith(\"--fallback=\")) {\n      options.fallbackGroup = arg.slice(\"--fallback=\".length);\n    } else {\n      throw new Error(`Unknown option: ${arg}`);\n    }\n  }\n\n  if ((options.route && !options.dir) || (!options.route && options.dir)) {\n    throw new Error(\"--route and --dir must be used together\");\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;\n}\n","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/itwanger/toBeBetterJavaer/blob/6617f5fd0b0597735bdc028f2fcd036817877327/scripts/sync-sidebar.js#L63-L99","documentation":"Thrown by the argument parser of scripts/sync-sidebar.js when a token matches none of the recognized options (--help/-h, --write, --check, --verbose, --sidebar, --route, --dir, --fallback and their =value forms). Unlike the convert script, this parser has no positional-argument branch, so EVERY unmatched token throws — including non-dash tokens.","triggerScenarios":"`node scripts/sync-sidebar.js --dry` (no dry-run concept; dry-run is default without --write); `node scripts/sync-sidebar.js docs/src/sidebar/itwanger/ai` (positional paths are not accepted here); typo like `--chek` for --check; missing `--` separator when running through npm.","commonSituations":"Assuming this script takes directory positional args like the image converter; typoed flags; npm swallowing flags (`npm run sidebar:check --check` instead of `npm run sidebar:check -- --check`).","solutions":["Run `node scripts/sync-sidebar.js --help` and use only listed options; pass directories via --dir, not positionally","Through npm, separate flags: `npm run sidebar:sync -- --check`","Drop dry-run style flags — omitting --write already means dry-run"],"exampleFix":"# before (positional dir not supported)\nnode scripts/sync-sidebar.js docs/src/sidebar/itwanger/ai\n\n# after\nnode scripts/sync-sidebar.js --route=/sidebar/itwanger/ai/ --dir=docs/src/sidebar/itwanger/ai","handlingStrategy":"validation","validationCode":"const ALLOWED = [\"--help\", \"-h\", \"--write\", \"--check\", \"--verbose\", \"--sidebar\", \"--route\", \"--dir\", \"--fallback\"];\nconst unknown = argv.filter((a) => !ALLOWED.some((o) => a === o || a.startsWith(o + \"=\")));\nif (unknown.length) throw new Error(`Not supported by sync-sidebar.js: ${unknown.join(\", \")}`);","typeGuard":null,"tryCatchPattern":"catch (err) { if (err.message.startsWith(\"Unknown option:\")) { execSync(\"node scripts/sync-sidebar.js --help\"); process.exit(2); } throw err; }","preventionTips":["This script takes NO positional args — directories go through --dir","Use npm run sidebar:sync -- <flags>","Dry-run is the default; do not pass a --dry-run flag"],"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"}