{"record":{"id":"5a2dc996d708ca28","repo":"wavetermdev/waveterm","slug":"file-too-large-for-editing-d-bytes-max-d","errorCode":null,"errorMessage":"file too large for editing: %d bytes (max: %d)","messagePattern":"file too large for editing: (.+?) bytes \\(max: (.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/util/fileutil/fileutil.go","lineNumber":349,"sourceCode":"\t\t\tfailed = true\n\t\t}\n\t}\n\n\treturn modifiedContents, results\n}\n\nfunc ReplaceInFile(filePath string, edits []EditSpec) error {\n\tfileInfo, err := os.Stat(filePath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to stat file: %w\", err)\n\t}\n\n\tif !fileInfo.Mode().IsRegular() {\n\t\treturn fmt.Errorf(\"not a regular file: %s\", filePath)\n\t}\n\n\tif fileInfo.Size() > MaxEditFileSize {\n\t\treturn fmt.Errorf(\"file too large for editing: %d bytes (max: %d)\", fileInfo.Size(), MaxEditFileSize)\n\t}\n\n\tcontents, err := os.ReadFile(filePath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to read file: %w\", err)\n\t}\n\n\tmodifiedContents, err := ApplyEdits(contents, edits)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif err := os.WriteFile(filePath, modifiedContents, fileInfo.Mode()); err != nil {\n\t\treturn fmt.Errorf(\"failed to write file: %w\", err)\n\t}\n\n\treturn nil\n}","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/util/fileutil/fileutil.go#L331-L367","documentation":"Returned when the file exceeds the maximum size allowed for in-memory editing, protecting against loading huge files. Both the actual size in bytes and the configured maximum are included in the message.","triggerScenarios":"Calling ReplaceInFile on a file whose os.Stat size exceeds 5*1024*1024 bytes.","commonSituations":"Editing large logs, generated code, lockfiles (package-lock.json), datasets, or binary-ish files that grew past 5 MB.","solutions":["Edit the file with a streaming tool (sed/awk) or process it line-by-line yourself.","Split the file and edit only the relevant portion.","Trim/generated content programmatically instead of text-editing it.","If legitimately needed, reduce the file below 5 MB or extend MaxEditFileSize in the library consciously (memory cost)."],"exampleFix":"// before\nfileutil.ReplaceInFile(\"huge.log\", edits) // 40 MB\n\n// after\nif fi, _ := os.Stat(path); fi.Size() > 5*1024*1024 {\n    return fmt.Errorf(\"use streaming edit for %s\", path)\n}\nfileutil.ReplaceInFile(path, edits)","handlingStrategy":"validation","validationCode":"const maxEdit = 5 * 1024 * 1024\nif fi, err := os.Stat(path); err == nil && fi.Size() > maxEdit {\n    return fmt.Errorf(\"%s is %d bytes; exceeds 5MB edit limit\", path, fi.Size())\n}","typeGuard":null,"tryCatchPattern":"// Go: fall back to streaming edit on size rejection\nif err := fileutil.ReplaceInFile(path, edits); err != nil {\n    if strings.Contains(err.Error(), \"file too large\") {\n        return streamingReplace(path, edits) // line-by-line implementation\n    }\n    return err\n}","preventionTips":["Stat the file and compare size to 5MB before editing","Use streaming tools (sed/awk) for logs and generated files","Don't text-edit lockfiles, datasets, or minified bundles","Route large files to a chunked or line-based editing path"],"tags":["go","filesystem","size-limit"],"backgroundTag":"file-too-large","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}