trpc/trpc · error · Error

Not working for ${file}

Error message

Not working for ${file}

What it means

script.push.ts writes the generated sponsors markdown into files bounded by <!-- SPONSORS:LIST:START --> and <!-- SPONSORS:LIST:END --> markers. It throws 'Not working for ${file}' when the START marker appears at or after the END marker (indexOf(start) >= indexOf(end)), meaning the markers are missing or out of order, which would make a blind replace corrupt the file.

Source

Thrown at www/src/components/sponsors/script.push.ts:157

  markdown.push(table);
}

const markdownStr = markdown.join('\n\n');
const rootPath = __dirname + '/../../../..';

const files = [
  `${rootPath}/README.md`,
  `${rootPath}/www/unversioned/_sponsors.mdx`,
];

for (const file of files) {
  const str = fs.readFileSync(file).toString();
  const start = '<!-- SPONSORS:LIST:START -->';
  const end = '<!-- SPONSORS:LIST:END -->';

  if (str.indexOf(start) >= str.indexOf(end)) {
    throw new Error(`Not working for ${file}`);
  }

  const newContents = str.replace(
    str.substring(str.indexOf(start) + start.length, str.lastIndexOf(end)),
    [
      '',
      '<!-- prettier-ignore-start -->',
      '<!-- markdownlint-disable -->',
      '',
      markdownStr,
      '',
      '<!-- markdownlint-restore -->',
      '<!-- prettier-ignore-end -->',
      '\n',
    ].join('\n'),
  );
  fs.writeFileSync(file, newContents);
}

View on GitHub (pinned to acff82332d)

Solutions

  1. Restore both markers in the affected file: <!-- SPONSORS:LIST:START --> ... <!-- SPONSORS:LIST:END --> with START before END.
  2. If a marker was deleted, copy the marker block from git history (git show HEAD:path).
  3. Ensure prettier/markdownlint is not configured to strip HTML comments in those files.
  4. Re-run the push script after fixing the markers.

Example fix

# before (END marker missing or before START)
<!-- SPONSORS:LIST:END -->
<!-- SPONSORS:LIST:START -->
# after
<!-- SPONSORS:LIST:START -->
... sponsors ...
<!-- SPONSORS:LIST:END -->
Defensive patterns

Strategy: validation

Validate before calling

// Verify markers before running the push script
const START = '<!-- SPONSORS:LIST:START -->';
const END = '<!-- SPONSORS:LIST:END -->';
for (const file of files) {
  const s = fs.readFileSync(file, 'utf8');
  if (s.indexOf(START) === -1 || s.indexOf(END) === -1 || s.indexOf(START) >= s.indexOf(END)) {
    throw new Error(`Markers malformed in ${file}`);
  }
}

Type guard

function hasValidMarkers(text: string): boolean {
  const s = text.indexOf('<!-- SPONSORS:LIST:START -->');
  const e = text.indexOf('<!-- SPONSORS:LIST:END -->');
  return s !== -1 && e !== -1 && s < e;
}

Prevention

When it happens

Trigger: Reading README.md or www/unversioned/_sponsors.mdx where the SPONSORS:LIST:START/END comment markers have been removed, reordered, or never added. indexOf returns -1 for a missing marker, and -1 >= -1 (or -1 >= realIndex) triggers the guard.

Common situations: A previous edit accidentally deleting a marker; markers reformatted by a linter that strips HTML comments; the file being replaced/reset without the marker template; a manual edit putting END before START.

Related errors


AI-assisted analysis of trpc/trpc@acff82332d (2026-08-12). Data as JSON: /api/errors/1af325a37fc433c1. Report an issue: GitHub.