ruvnet/ruflo · warning · Error

File too large: ${code.length} bytes exceeds ${this.config.m

Error message

File too large: ${code.length} bytes exceeds ${this.config.maxFileSize}

What it means

Thrown by ASTAnalyzer.analyze(code, filePath) when code.length exceeds config.maxFileSize (default 1 MiB). This is a guard before the regex/line-scan parsing runs, because the per-line heuristics in matchFunction/matchClass are O(lines) and blow up on minified or generated files. It throws synchronously before touching the cache or the optional @ruvector/ast native engine.

Source

Thrown at v3/@claude-flow/cli/src/ruvector/ast-analyzer.ts:87

  }

  async initialize(): Promise<void> {
    try {
      // @ruvector/ast is optional - gracefully fallback if not installed
      const ruvector = await import('@ruvector/ast' as string).catch(() => null);
      if (ruvector) {
        this.ruvectorEngine = (ruvector as any).createASTAnalyzer?.(this.config);
        this.useNative = !!this.ruvectorEngine;
      }
    } catch {
      this.useNative = false;
    }
  }

  analyze(code: string, filePath: string = 'unknown'): ASTAnalysis {
    const startTime = performance.now();
    if (code.length > this.config.maxFileSize) {
      throw new Error(`File too large: ${code.length} bytes exceeds ${this.config.maxFileSize}`);
    }
    const cacheKey = this.getCacheKey(code, filePath);
    const cached = this.analysisCache.get(cacheKey);
    if (cached) return cached;
    const language = this.detectLanguage(code, filePath);
    const root = this.parseAST(code, language);
    const functions = this.extractFunctions(root);
    const classes = this.extractClasses(root);
    const imports = this.extractImports(code, language);
    const exports = this.extractExports(code, language);
    const complexity = this.calculateComplexity(code, root);
    const durationMs = performance.now() - startTime;
    const analysis: ASTAnalysis = {
      filePath, language, root, functions, classes, imports, exports,
      complexity, timestamp: Date.now(), durationMs,
    };
    this.analysisCache.set(cacheKey, analysis);
    return analysis;

View on GitHub (pinned to 6b01dc5a68)

Solutions

  1. Skip analyze for known large/generated paths (dist/, build/, *.min.js, vendor/) before calling.
  2. Raise maxFileSize in the ASTAnalyzer config if you genuinely need to analyze large files: new ASTAnalyzer({ maxFileSize: 5 * 1024 * 1024 }).
  3. Pre-split very large files (per-function or per-export) and analyze the chunks.
  4. Stream/skip minified files — AST heuristics produce low-quality results on them anyway.

Example fix

// before
const analyzer = new ASTAnalyzer();
const a = analyzer.analyze(fs.readFileSync(bigBundle, 'utf-8'), bigBundle);

// after — raise the cap AND skip generated paths
const analyzer = new ASTAnalyzer({ maxFileSize: 8 * 1024 * 1024 });
if (/\.(min|bundle)\.js$|\/dist\//.test(bigBundle)) return null;
const a = analyzer.analyze(fs.readFileSync(bigBundle, 'utf-8'), bigBundle);
Defensive patterns

Strategy: validation

Validate before calling

import { createASTAnalyzer } from './ast-analyzer';

const SKIP_RE = /\/(dist|build|node_modules|vendor)\/|\.(min|bundle)\.(js|ts)$/;

function analyzeSafe(filePath: string) {
  if (SKIP_RE.test(filePath)) return null;               // skip generated/minified
  const code = fs.readFileSync(filePath, 'utf-8');
  const cap = Math.min(code.length, 1024 * 1024);
  if (code.length > cap) {
    // raise the cap only for files you trust to be real source
    return new (createASTAnalyzer({ maxFileSize: 8 * 1024 * 1024 }).constructor)({ maxFileSize: 8 * 1024 * 1024 }).analyze(code, filePath);
  }
  return createASTAnalyzer().analyze(code, filePath);
}

Type guard

function isWithinSizeLimit(code: string, max = 1024 * 1024): boolean {
  return typeof code === 'string' && code.length <= max;
}

Try / catch

try {
  return analyzer.analyze(code, filePath);
} catch (e) {
  if (/File too large/.test(String(e))) {
    // Skip rather than crash the caller — large/generated files yield poor heuristics anyway.
    return null;
  }
  throw e;
}

Prevention

When it happens

Trigger: Analyzing a bundled/minified JS file (webpack/rollup output, often >1 MiB); passing a generated file (auto-generated protobuf, OpenAPI client, schema dumps); reading a large data file mislabeled as source; analyzing vendored deps; the analyzer is pointed at node_modules by accident.

Common situations: Hook runs analyze() on every save and a developer opens a built bundle; tool that walks the whole repo without an ignore list picks up dist/ or vendor/; a monorepo's lockfile is misdetected as a source file.

Related errors


AI-assisted analysis of ruvnet/ruflo@6b01dc5a68 (2026-08-12). Data as JSON: /api/errors/aa36329b3fd38a32. Report an issue: GitHub.