affaan-m/ECC · error · Error

is too large (maximum bytes).

Error message

${label} is too large (maximum ${maxBytes} bytes).

What it means

readRegularTextFile reads a file within the memory vault in bounded chunks and enforces a hard size cap (maxBytes). When the accumulated byte count exceeds maxBytes it throws this error instead of loading an oversized file into memory. This protects the vault from unbounded reads of corrupted or user-swapped files.

Solutions

  1. Reduce the file's size below maxBytes (trim or split the document).
  2. Remove or replace the oversized file (e.g. the project memory .gitignore) and let the library recreate it.
  3. If legitimately needed, re-invoke with a higher maxBytes option where the API exposes it.

Example fix

// before
const content = readRegularTextFile(bigDoc, { label: 'doc', maxBytes: 1024 });
// after
const content = readRegularTextFile(bigDoc, { label: 'doc', maxBytes: 64 * 1024 }); // raise cap or trim file first
Defensive patterns

Strategy: validation

Validate before calling

const stat = fs.statSync(filePath);
if (stat.size > maxBytes) throw new Error(`Refusing to read ${filePath}: ${stat.size} bytes exceeds ${maxBytes}.`);

Type guard

const isWithinSizeLimit = (filePath, maxBytes) => { try { return fs.statSync(filePath).size <= maxBytes; } catch { return false; } };

Try / catch

try {
  const content = readRegularTextFile(filePath, { label, maxBytes, trustedRoot });
} catch (err) {
  if (err.message.includes('is too large')) {
    // handle oversize: truncate, split, or raise the cap deliberately
  } else throw err;
}

Prevention

When it happens

Trigger: Calling any vault API that reads a text document (e.g. saveMemory's .gitignore check, or document loading paths via readBody/existing) when the target file's size exceeds maxBytes (MAX_DOCUMENT_BYTES for project memory documents).

Common situations: A .gitignore or memory .md file was replaced with a much larger file outside the library; a user pasted a huge document into the vault manually; syncing tools (Dropbox, git LFS checkout issues) expanded files unexpectedly.

Understand the failure class

Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/bd5663712216302d. Report an issue: GitHub.

Appendix: source

Thrown at scripts/lib/memory-vault.js:183

    }
    if (options.trustedRoot) {
      assertWithinTrustedRoot(filePath, options.trustedRoot, `read ${label}`);
    }
    if (opened.size > BigInt(maxBytes)) {
      throw new Error(`${label} is too large (${opened.size} bytes).`);
    }

    const chunks = [];
    let total = 0;
    while (total <= maxBytes) {
      const buffer = Buffer.alloc(Math.min(64 * 1024, maxBytes + 1 - total));
      const bytesRead = fs.readSync(descriptor, buffer, 0, buffer.length, null);
      if (bytesRead === 0) break;
      chunks.push(buffer.subarray(0, bytesRead));
      total += bytesRead;
    }
    if (total > maxBytes) {
      throw new Error(`${label} is too large (maximum ${maxBytes} bytes).`);
    }
    return decodeUtf8(Buffer.concat(chunks, total), label);
  } finally {
    fs.closeSync(descriptor);
  }
}

function writeCreateOnlyTextFile(filePath, content, trustedRoot) {
  assertWithinTrustedRoot(filePath, trustedRoot, 'write memory');
  const temporaryPath = path.join(
    path.dirname(filePath),
    `.ecc-memory-${process.pid}-${crypto.randomUUID()}.tmp`
  );
  const flags = fs.constants.O_WRONLY
    | fs.constants.O_CREAT
    | fs.constants.O_EXCL
    | (fs.constants.O_NOFOLLOW || 0);
  let descriptor;

View on GitHub (pinned to 8321021c54)