itwanger/toBeBetterJavaer · error · Error

Could not parse route array: ${route}

Error message

Could not parse route array: ${route}

What it means

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.

Source

Thrown at scripts/sync-sidebar.js:384

  return null;
}

function findLineStart(source, index) {
  const lineBreak = source.lastIndexOf("\n", index);
  return lineBreak === -1 ? 0 : lineBreak + 1;
}

function findRouteArray(source, route) {
  const routePattern = new RegExp(`(["'])${escapeRegExp(route)}\\1\\s*:\\s*\\[`);
  const match = routePattern.exec(source);
  if (!match) {
    return null;
  }

  const arrayStart = match.index + match[0].lastIndexOf("[");
  const arrayEnd = findMatchingBracket(source, arrayStart);
  if (arrayEnd === -1) {
    throw new Error(`Could not parse route array: ${route}`);
  }
  return { start: arrayStart, end: arrayEnd };
}

function findMatchingBracket(source, openIndex) {
  let depth = 0;
  let quote = null;
  let escaped = false;
  let lineComment = false;
  let blockComment = false;

  for (let index = openIndex; index < source.length; index += 1) {
    const char = source[index];
    const next = source[index + 1];

    if (lineComment) {
      if (char === "\n") {
        lineComment = false;

View on GitHub (pinned to 6617f5fd0b)

Solutions

  1. 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
  2. If a merge conflict left artifacts, resolve them and rerun
  3. After fixing, rerun sync-sidebar — the dry-run default makes verification safe

Example fix

// sidebar.ts — before: missing closing bracket
"/sidebar/itwanger/ai/": [
  "page-one",
  "page-two",

// after
"/sidebar/itwanger/ai/": [
  "page-one",
  "page-two",
],
Defensive patterns

Strategy: validation

Validate before calling

// Syntax-check sidebar.ts before syncing (unbalanced brackets fail fast with a location)
const { execSync } = require("child_process");
try { execSync(`node --check "${sidebarPath}"`, { stdio: "pipe" }); } catch (e) { console.error("sidebar.ts has a syntax error — fix brackets first"); process.exit(2); }

Try / catch

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; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of itwanger/toBeBetterJavaer@6617f5fd0b (2026-08-14). Data as JSON: /api/errors/38aa3e0ae3dc5fa3. Report an issue: GitHub.