{"record":{"id":"0d941f5aa5a8f06d","repo":"itwanger/toBeBetterJavaer","slug":"route-not-found-in-sidebar-ts-target-route","errorCode":null,"errorMessage":"Route not found in sidebar.ts: ${target.route}","messagePattern":"Route not found in sidebar\\.ts: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/sync-sidebar.js","lineNumber":187,"sourceCode":"\nfunction syncTarget(source, target) {\n  const dir = path.resolve(ROOT_DIR, target.dir);\n  const report = {\n    route: target.route,\n    dir: path.relative(ROOT_DIR, dir),\n    added: [],\n    removed: [],\n    warnings: [],\n  };\n\n  if (!fs.existsSync(dir)) {\n    throw new Error(`Markdown directory not found: ${target.dir}`);\n  }\n\n  const files = collectMarkdownSlugs(dir);\n  const blockRange = findRouteArray(source, target.route);\n  if (!blockRange) {\n    throw new Error(`Route not found in sidebar.ts: ${target.route}`);\n  }\n\n  let block = source.slice(blockRange.start, blockRange.end + 1);\n  const refs = collectRefs(block);\n  const listedSlugs = new Set(refs.map((ref) => ref.slug));\n  const fileSlugs = new Set(files.map((file) => file.slug));\n\n  const staleSlugs = [...listedSlugs].filter((slug) => !fileSlugs.has(slug));\n  if (staleSlugs.length > 0) {\n    const removal = removeStaleStringEntries(block, staleSlugs);\n    block = removal.block;\n    report.removed = removal.removed;\n\n    for (const slug of staleSlugs) {\n      if (!removal.removed.includes(slug)) {\n        report.warnings.push(`Stale ref \"${slug}\" is not a plain string entry; remove it manually if needed.`);\n      }\n    }","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/itwanger/toBeBetterJavaer/blob/6617f5fd0b0597735bdc028f2fcd036817877327/scripts/sync-sidebar.js#L169-L205","documentation":"Thrown by syncTarget() in scripts/sync-sidebar.js when findRouteArray() cannot locate the target route as a key in sidebar.ts. The lookup is a literal regex: a quoted string equal to the route (normalized with leading/trailing slashes) followed by optional whitespace, a colon, and an opening bracket. Any deviation in the sidebar source — different quoting, template literal, or extra whitespace before the colon beyond what \\s* allows — makes the route invisible.","triggerScenarios":"Route key in sidebar.ts spelled differently (`/sidebar/itwanger/ai` without trailing slash, or a deeper/shallower path) than the --route value; the key exists but its value is not an array literal (`route: someVariable`); quoting mismatch (backtick template literal vs quote); route genuinely not yet added to sidebar.ts.","commonSituations":"Adding a new content section and running sync before creating the sidebar entry; refactoring sidebar.ts to computed keys or spread objects; trailing-slash inconsistency between the CLI arg and the file.","solutions":["Open sidebar.ts, find the target section, and make sure it has a literal key exactly like `\"/sidebar/itwanger/ai/\": [` — quotes, slashes, colon, bracket","Match your --route to the existing key exactly (normalizeRoute adds surrounding slashes automatically)","If the section is new, first add an empty array entry for the route in sidebar.ts, then run sync to populate it"],"exampleFix":"// sidebar.ts — before: no such route key\nexport const sidebar = {\n  \"/sidebar/itwanger/\": { /* ... */ },\n};\n\n// after: add the route as a literal array so sync can populate it\nexport const sidebar = {\n  \"/sidebar/itwanger/\": { /* ... */ },\n  \"/sidebar/itwanger/ai/\": [],\n};","handlingStrategy":"type-guard","validationCode":"// Confirm the route key exists as a literal array before running sync\nconst src = fs.readFileSync(sidebarPath, \"utf8\");\nconst re = new RegExp([\"([\\\\\\\"'])\"].join(\"\") + route.replace(/\\//g, \"\\\\/\") + \"\\\\1\\\\s*:\\\\s*\\\\[\");\nif (!re.test(src)) console.error(`Add \\\"${route}\\\": [] to sidebar.ts first`);","typeGuard":"const routeExistsInSidebar = (src, route) => new RegExp(`([\"'])${route.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")}\\\\1\\\\s*:\\\\s*\\\\[`).test(src);","tryCatchPattern":"catch (err) { if (err.message.startsWith(\"Route not found in sidebar.ts:\")) { console.error(\"Create the route entry as a literal quoted key with an array value, then rerun\"); process.exit(2); } throw err; }","preventionTips":["Add the empty route array to sidebar.ts before syncing a new section","Keep route keys as plain quoted strings with array literals — no computed keys or indirection","Match trailing slashes: normalizeRoute enforces leading and trailing slashes on --route"],"tags":["parsing","configuration","sidebar","regex"],"backgroundTag":null,"analyzedSha":"6617f5fd0b0597735bdc028f2fcd036817877327","analyzedAt":"2026-08-14T14:50:55.107Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}