{"record":{"id":"03cdfe55a15938cc","repo":"kovidgoyal/kitty","slug":"file-size-s-is-too-large-for-performant-editing","errorCode":null,"errorMessage":"File size %s is too large for performant editing","messagePattern":"File size (.+?) is too large for performant editing","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"tools/cmd/edit_in_kitty/main.go","lineNumber":191,"sourceCode":"\t\t}\n\t\treturn 1, &tui.KilledBySignal{Msg: fmt.Sprint(\"Killed by signal: \", ds), SignalName: ds}\n\t}\n\treturn\n}\n\nfunc edit_in_kitty(path string, opts *Options) (exit_code int, err error) {\n\tread_file, err := os.Open(path)\n\tif err != nil {\n\t\treturn 1, fmt.Errorf(\"Failed to open %s for reading with error: %w\", path, err)\n\t}\n\tdefer read_file.Close()\n\tvar s unix.Stat_t\n\terr = unix.Fstat(int(read_file.Fd()), &s)\n\tif err != nil {\n\t\treturn 1, fmt.Errorf(\"Failed to stat %s with error: %w\", path, err)\n\t}\n\tif s.Size > int64(opts.MaxFileSize)*1024*1024 {\n\t\treturn 1, fmt.Errorf(\"File size %s is too large for performant editing\", humanize.Bytes(uint64(s.Size)))\n\t}\n\n\tfile_data, err := io.ReadAll(read_file)\n\tif err != nil {\n\t\treturn 1, fmt.Errorf(\"Failed to read from %s with error: %w\", path, err)\n\t}\n\tread_file.Close()\n\tdata := strings.Builder{}\n\tdata.Grow(len(file_data) * 4)\n\n\tadd := func(key, val string) {\n\t\tif data.Len() > 0 {\n\t\t\tdata.WriteString(\",\")\n\t\t}\n\t\tdata.WriteString(key)\n\t\tdata.WriteString(\"=\")\n\t\tdata.WriteString(val)\n\t}","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/tools/cmd/edit_in_kitty/main.go#L173-L209","documentation":"edit_in_kitty enforces a size cap: if the file exceeds opts.MaxFileSize (interpreted as MiB), it refuses to edit it, reporting the humanized size. This is a deliberate performance guard — loading and editing huge files in the kitty editor would be slow or exhaust memory.","triggerScenarios":"Opening a file larger than the configured MaxFileSize MiB; opts.MaxFileSize defaults to a modest value, so multi-hundred-MiB logs, data dumps, or datasets trigger it immediately.","commonSituations":"Trying to edit large log files, CSV/JSON exports, database dumps, or core-dump-adjacent files; or a user lowering MaxFileSize and forgetting files previously editable now trip the limit.","solutions":["Edit the file with a tool built for large files (less, vim with lazy loading, sed/awk for targeted changes)","Raise the --max-file-size option if you genuinely need kitty editing and have RAM to spare","Split the file (split, head/tail ranges) and edit the relevant chunk"],"exampleFix":"# before\nedit-in-kitty huge.log\n# after\nedit-in-kitty --max-file-size 2048 huge.log   # or: edit only a slice\nedit-in-kitty <(sed -n '1,100000p' huge.log)","handlingStrategy":"validation","validationCode":"// Check size against the cap before invoking the editor\nconst maxMiB = 100\nif info, err := os.Stat(path); err == nil && info.Size() > maxMiB<<20 {\n    fmt.Fprintf(os.Stderr, \"%s is %d MiB; cap is %d\\n\", path, info.Size()>>20, maxMiB)\n    os.Exit(1)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Surface MaxFileSize in user-facing config so the cap isn't a surprise","Route big files to streaming editors (less, sed) in wrapper scripts"],"tags":["file-size","limits","performance","go"],"backgroundTag":"file-too-large","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}