{"record":{"id":"38aa3e0ae3dc5fa3","repo":"itwanger/toBeBetterJavaer","slug":"could-not-parse-route-array-route","errorCode":null,"errorMessage":"Could not parse route array: ${route}","messagePattern":"Could not parse route array: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/sync-sidebar.js","lineNumber":384,"sourceCode":"  return null;\n}\n\nfunction findLineStart(source, index) {\n  const lineBreak = source.lastIndexOf(\"\\n\", index);\n  return lineBreak === -1 ? 0 : lineBreak + 1;\n}\n\nfunction findRouteArray(source, route) {\n  const routePattern = new RegExp(`([\"'])${escapeRegExp(route)}\\\\1\\\\s*:\\\\s*\\\\[`);\n  const match = routePattern.exec(source);\n  if (!match) {\n    return null;\n  }\n\n  const arrayStart = match.index + match[0].lastIndexOf(\"[\");\n  const arrayEnd = findMatchingBracket(source, arrayStart);\n  if (arrayEnd === -1) {\n    throw new Error(`Could not parse route array: ${route}`);\n  }\n  return { start: arrayStart, end: arrayEnd };\n}\n\nfunction findMatchingBracket(source, openIndex) {\n  let depth = 0;\n  let quote = null;\n  let escaped = false;\n  let lineComment = false;\n  let blockComment = false;\n\n  for (let index = openIndex; index < source.length; index += 1) {\n    const char = source[index];\n    const next = source[index + 1];\n\n    if (lineComment) {\n      if (char === \"\\n\") {\n        lineComment = false;","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/itwanger/toBeBetterJavaer/blob/6617f5fd0b0597735bdc028f2fcd036817877327/scripts/sync-sidebar.js#L366-L402","documentation":"Thrown by findRouteArray() in scripts/sync-sidebar.js when the route key IS found and its opening '[' is located, but findMatchingBracket() cannot find the matching ']' by scanning to the end of the file. The scanner tracks nesting depth, string quotes, escapes, and line/block comments, so an unbalanced bracket — or a bracket appearing only inside what the scanner treats as a string/comment — leaves depth > 0 forever.","triggerScenarios":"An unclosed '[' or '(' inside the route's array (syntax error in sidebar.ts itself); an unbalanced quote earlier in the array causing the rest of the file to be consumed as a string; an intentional ']' inside a string whose opening quote is malformed; truncated file.","commonSituations":"Hand-editing sidebar.ts and dropping a closing bracket; merge conflicts in sidebar.ts leaving stray brackets or quote fragments; a string in a sidebar entry containing an unescaped quote character.","solutions":["Run a syntax check on sidebar.ts: `node --check docs/src/.vuepress/sidebar.ts` or open it in an editor with bracket matching to find the unbalanced bracket","If a merge conflict left artifacts, resolve them and rerun","After fixing, rerun sync-sidebar — the dry-run default makes verification safe"],"exampleFix":"// sidebar.ts — before: missing closing bracket\n\"/sidebar/itwanger/ai/\": [\n  \"page-one\",\n  \"page-two\",\n\n// after\n\"/sidebar/itwanger/ai/\": [\n  \"page-one\",\n  \"page-two\",\n],","handlingStrategy":"validation","validationCode":"// Syntax-check sidebar.ts before syncing (unbalanced brackets fail fast with a location)\nconst { execSync } = require(\"child_process\");\ntry { execSync(`node --check \"${sidebarPath}\"`, { stdio: \"pipe\" }); } catch (e) { console.error(\"sidebar.ts has a syntax error — fix brackets first\"); process.exit(2); }","typeGuard":null,"tryCatchPattern":"catch (err) { if (err.message.startsWith(\"Could not parse route array:\")) { console.error(\"sidebar.ts likely has an unbalanced bracket or broken string — run node --check on it\"); process.exit(2); } throw err; }","preventionTips":["Let the editor's bracket matching / Prettier validate sidebar.ts after hand edits","Resolve merge conflicts fully before running sidebar:sync","Keep strings inside array entries simple; escape quotes rather than nesting them"],"tags":["parsing","sidebar","syntax-error","bracket-matching"],"backgroundTag":null,"analyzedSha":"6617f5fd0b0597735bdc028f2fcd036817877327","analyzedAt":"2026-08-14T14:50:55.107Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}