diegosouzapw/OmniRoute · error · Error

Local corpus file is not valid text

Error message

Local corpus file is not valid text

What it means

The file was read as UTF-8 and its content contains a NUL byte (\0), the binary-file sentinel. The corpus only serves text files, so this marks the file as binary and refuses to index/return it; the path, extension and size checks all passed.

Solutions

  1. Exclude binary files from corpus reads
  2. Filter binary extensions in allowedExtensions
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/lib/localCorpus/index.ts:578 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25). Data as JSON: /api/errors/44be892ebc3481e8. Report an issue: GitHub.

Appendix: source

Thrown at src/lib/localCorpus/index.ts:578

    }

    let canonicalFile: string;
    try {
      canonicalFile = await fs.realpath(resolved);
    } catch {
      throw new Error("Local corpus file is not accessible");
    }
    if (!isContained(root, canonicalFile)) {
      throw new Error("Local corpus file path escapes the configured root");
    }

    let content: string;
    try {
      content = await fs.readFile(canonicalFile, "utf8");
    } catch {
      throw new Error("Local corpus file is not accessible");
    }
    if (content.includes("\0")) throw new Error("Local corpus file is not valid text");

    const lines = content.split(/\r?\n/);
    const requestedStart = positiveInteger(options.startLine, 1);
    const requestedEnd = positiveInteger(
      options.endLine,
      requestedStart + this.limits.maxReadLines - 1
    );
    if (requestedEnd < requestedStart) {
      throw new Error("Local corpus endLine must be greater than or equal to startLine");
    }

    const startLine = Math.min(requestedStart, Math.max(lines.length, 1));
    const endLine = Math.min(lines.length, requestedEnd, startLine + this.limits.maxReadLines - 1);
    return {
      relativePath: normalizeRelativePath(path.relative(root, canonicalFile)),
      content: lines.slice(startLine - 1, endLine).join("\n"),
      startLine,
      endLine,

View on GitHub (pinned to a179ffed5b)