{"record":{"id":"aa36329b3fd38a32","repo":"ruvnet/ruflo","slug":"file-too-large-code-length-bytes-exceeds-thi","errorCode":null,"errorMessage":"File too large: ${code.length} bytes exceeds ${this.config.maxFileSize}","messagePattern":"File too large: (.+?) bytes exceeds (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"v3/@claude-flow/cli/src/ruvector/ast-analyzer.ts","lineNumber":87,"sourceCode":"  }\n\n  async initialize(): Promise<void> {\n    try {\n      // @ruvector/ast is optional - gracefully fallback if not installed\n      const ruvector = await import('@ruvector/ast' as string).catch(() => null);\n      if (ruvector) {\n        this.ruvectorEngine = (ruvector as any).createASTAnalyzer?.(this.config);\n        this.useNative = !!this.ruvectorEngine;\n      }\n    } catch {\n      this.useNative = false;\n    }\n  }\n\n  analyze(code: string, filePath: string = 'unknown'): ASTAnalysis {\n    const startTime = performance.now();\n    if (code.length > this.config.maxFileSize) {\n      throw new Error(`File too large: ${code.length} bytes exceeds ${this.config.maxFileSize}`);\n    }\n    const cacheKey = this.getCacheKey(code, filePath);\n    const cached = this.analysisCache.get(cacheKey);\n    if (cached) return cached;\n    const language = this.detectLanguage(code, filePath);\n    const root = this.parseAST(code, language);\n    const functions = this.extractFunctions(root);\n    const classes = this.extractClasses(root);\n    const imports = this.extractImports(code, language);\n    const exports = this.extractExports(code, language);\n    const complexity = this.calculateComplexity(code, root);\n    const durationMs = performance.now() - startTime;\n    const analysis: ASTAnalysis = {\n      filePath, language, root, functions, classes, imports, exports,\n      complexity, timestamp: Date.now(), durationMs,\n    };\n    this.analysisCache.set(cacheKey, analysis);\n    return analysis;","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/v3/@claude-flow/cli/src/ruvector/ast-analyzer.ts#L69-L105","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Skip analyze for known large/generated paths (dist/, build/, *.min.js, vendor/) before calling.","Raise maxFileSize in the ASTAnalyzer config if you genuinely need to analyze large files: new ASTAnalyzer({ maxFileSize: 5 * 1024 * 1024 }).","Pre-split very large files (per-function or per-export) and analyze the chunks.","Stream/skip minified files — AST heuristics produce low-quality results on them anyway."],"exampleFix":"// before\nconst analyzer = new ASTAnalyzer();\nconst a = analyzer.analyze(fs.readFileSync(bigBundle, 'utf-8'), bigBundle);\n\n// after — raise the cap AND skip generated paths\nconst analyzer = new ASTAnalyzer({ maxFileSize: 8 * 1024 * 1024 });\nif (/\\.(min|bundle)\\.js$|\\/dist\\//.test(bigBundle)) return null;\nconst a = analyzer.analyze(fs.readFileSync(bigBundle, 'utf-8'), bigBundle);","handlingStrategy":"validation","validationCode":"import { createASTAnalyzer } from './ast-analyzer';\n\nconst SKIP_RE = /\\/(dist|build|node_modules|vendor)\\/|\\.(min|bundle)\\.(js|ts)$/;\n\nfunction analyzeSafe(filePath: string) {\n  if (SKIP_RE.test(filePath)) return null;               // skip generated/minified\n  const code = fs.readFileSync(filePath, 'utf-8');\n  const cap = Math.min(code.length, 1024 * 1024);\n  if (code.length > cap) {\n    // raise the cap only for files you trust to be real source\n    return new (createASTAnalyzer({ maxFileSize: 8 * 1024 * 1024 }).constructor)({ maxFileSize: 8 * 1024 * 1024 }).analyze(code, filePath);\n  }\n  return createASTAnalyzer().analyze(code, filePath);\n}","typeGuard":"function isWithinSizeLimit(code: string, max = 1024 * 1024): boolean {\n  return typeof code === 'string' && code.length <= max;\n}","tryCatchPattern":"try {\n  return analyzer.analyze(code, filePath);\n} catch (e) {\n  if (/File too large/.test(String(e))) {\n    // Skip rather than crash the caller — large/generated files yield poor heuristics anyway.\n    return null;\n  }\n  throw e;\n}","preventionTips":["Maintain an ignore list (dist/, build/, node_modules/, *.min.js) and skip before analyzing.","Pass { maxFileSize } to the ASTAnalyzer constructor when you legitimately analyze large source.","Don't feed generated files (protobuf/OpenAPI output) to the heuristic parser — quality is low even when it doesn't throw."],"tags":["ast","size-limit","analysis","configuration"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}