{"record":{"id":"13c5ca9f0558b133","repo":"itwanger/toBeBetterJavaer","slug":"route-and-dir-must-be-used-together","errorCode":null,"errorMessage":"--route and --dir must be used together","messagePattern":"--route and --dir must be used together","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/sync-sidebar.js","lineNumber":86,"sourceCode":"    } 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\nfunction normalizeRoute(route) {\n  if (!route.startsWith(\"/\")) {\n    route = `/${route}`;\n  }\n  if (!route.endsWith(\"/\")) {","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/itwanger/toBeBetterJavaer/blob/6617f5fd0b0597735bdc028f2fcd036817877327/scripts/sync-sidebar.js#L68-L104","documentation":"Thrown by parseArgs() in scripts/sync-sidebar.js after the flag loop when exactly one of --route/--dir is provided. The two options form a pair: the route names the sidebar.ts keys entry (normalized to leading and trailing slashes) and the dir names the Markdown directory whose slugs sync into that route's array.","triggerScenarios":"`--route=/sidebar/itwanger/ai/` without --dir; `--dir=docs/src/sidebar/itwanger/ai` without --route; a typo'd `--dirs=` lands in the unknown-option branch instead, so this error specifically means one valid member of the pair is present alone.","commonSituations":"Quick one-off invocations where only the directory is pasted in; copy-pasting half of a documented example command; forgetting that omitting BOTH is valid (falls back to DEFAULT_TARGETS).","solutions":["Supply both: `--route=/sidebar/itwanger/ai/ --dir=docs/src/sidebar/itwanger/ai`","Or drop both to sync the built-in default target","Note normalizeRoute adds surrounding slashes for you, so `--route sidebar/itwanger/ai` also works"],"exampleFix":"# before\nnode scripts/sync-sidebar.js --dir=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 hasRoute = args.some((a) => a === \"--route\" || a.startsWith(\"--route=\"));\nconst hasDir = args.some((a) => a === \"--dir\" || a.startsWith(\"--dir=\"));\nif (hasRoute !== hasDir) throw new Error(\"Pass both --route and --dir, or neither (defaults are used)\");","typeGuard":null,"tryCatchPattern":"catch (err) { if (err.message === \"--route and --dir must be used together\") { console.error(\"Add the missing half of the pair (see --help)\"); process.exit(2); } throw err; }","preventionTips":["Copy full example commands (--route X --dir Y) from --help, never half","Omit both to sync the built-in default target","Wrap common invocations in package.json scripts"],"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"}