{"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":null,"httpStatus":null,"severity":"error","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/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/cli/src/ruvector/ast-analyzer.ts#L69-L105","documentation":"ASTAnalyzer.analyze() refuses to parse source above config.maxFileSize bytes to protect the parser from pathological inputs. The default cap is 1,048,576 (1 MiB), set at ast-analyzer.ts:46; the check uses code.length (UTF-16 code units), so files heavy in non-ASCII characters hit the cap even when their byte size on disk is similar.","triggerScenarios":"Calling analyze() on minified bundles, lockfile-scale sources, or generated files over 1 MiB; raising nothing and feeding dist/*.js; analyzing a file where code.length counts surrogate pairs, crossing the limit near ~1M characters.","commonSituations":"Running AST analysis over an entire repo including dist/ and node_modules artifacts; vendored SDK bundles; snapshot or fixture files; defaults left untouched because the config object was constructed partially.","solutions":["Exclude or chunk the offending file — analyze per-module sources instead of bundles","Pass a higher maxFileSize in the analyzer config: { maxFileSize: 4 * 1024 * 1024 } (constructor/createASTAnalyzer accepts it)","Skip known-generated paths (dist, build, *.min.js) before analysis","Pre-check size and log a warning rather than letting analyze() throw mid-batch"],"exampleFix":"// before\nconst result = analyzer.analyze(code, filePath); // throws on >1MiB files\n// after\nconst MAX = 1024 * 1024;\nif (code.length > MAX) {\n  console.warn(`skipping ${filePath}: ${code.length} > ${MAX} chars`);\n} else {\n  const result = analyzer.analyze(code, filePath);\n}\n// or raise the cap:\n// const analyzer = new ASTAnalyzer({ maxFileSize: 4 * 1024 * 1024 });","handlingStrategy":"validation","validationCode":"const MAX_CHARS = 1024 * 1024; // default maxFileSize, ast-analyzer.ts:46\nfunction analyzeSafe(analyzer: { analyze(c: string, f?: string): unknown }, code: string, filePath: string) {\n  if (code.length > MAX_CHARS) return null; // caller skips or chunks\n  return analyzer.analyze(code, filePath);\n}","typeGuard":"const isWithinSizeLimit = (code: string, max = 1024 * 1024): boolean => code.length <= max;","tryCatchPattern":"try {\n  result = analyzer.analyze(code, filePath);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('File too large')) {\n    result = null; // skip oversized file, keep the batch alive\n  } else throw e;\n}","preventionTips":["Exclude dist/, build/, *.min.js and vendor bundles from AST analysis passes","If you raise maxFileSize, profile first — the cap protects parser time and memory","Check code.length (UTF-16 units), not Buffer.byteLength, to mirror the library's check"],"tags":["ast","static-analysis","file-size","limit","config"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}