{"record":{"id":"b003e351f25012ca","repo":"kovidgoyal/kitty","slug":"failed-to-write-image-data-to-temp-file-for-transm","errorCode":null,"errorMessage":"Failed to write image data to temp file for transmission: %w","messagePattern":"Failed to write image data to temp file for transmission: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kittens/icat/transmit.go","lineNumber":144,"sourceCode":"\tvar data_size int\n\tif frame.in_memory_bytes == nil {\n\t\tfname, err = filepath.Abs(frame.filename)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to convert image data output file: %s to absolute path with error: %w\", frame.filename, err)\n\t\t}\n\t\tframe.filename = \"\" // so it isn't deleted in cleanup\n\t} else {\n\t\tis_temp = true\n\t\tf, err := images.CreateTempInRAM()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to create a temp file for image data transmission: %w\", err)\n\t\t}\n\t\tdata_size = len(frame.in_memory_bytes)\n\t\t_, err = bytes.NewBuffer(frame.in_memory_bytes).WriteTo(f)\n\t\tf.Close()\n\t\tif err != nil {\n\t\t\tos.Remove(f.Name())\n\t\t\treturn fmt.Errorf(\"Failed to write image data to temp file for transmission: %w\", err)\n\t\t}\n\t\tfname = f.Name()\n\t}\n\tgc := gc_for_image(imgd, frame_num, frame)\n\tgc.SetTransmission(utils.IfElse(is_temp, graphics.GRT_transmission_tempfile, graphics.GRT_transmission_file))\n\tif data_size > 0 {\n\t\tgc.SetDataSize(uint64(data_size))\n\t}\n\treturn gc.WriteWithPayloadTo(os.Stdout, utils.UnsafeStringToBytes(fname))\n}\n\nfunc transmit_stream(imgd *image_data, frame_num int, frame *image_frame) (err error) {\n\tdata := frame.in_memory_bytes\n\tif data == nil {\n\t\tdata, err = os.ReadFile(frame.filename)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to read image data output file: %s with error: %w\", frame.filename, err)\n\t\t}","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kittens/icat/transmit.go#L126-L162","documentation":"Raised by transmit_file in the icat kitten when image data held in memory cannot be written to a temporary file before being transmitted to the terminal. The temp file is used when the image frame exists only as in-memory bytes rather than a file on disk. The error wraps the underlying os write failure.","triggerScenarios":"Calling the icat kitten with an image supplied via stdin or an in-memory frame (e.g. from a pipe or processed image) when the temp directory is not writable or the disk is full. bytes.NewBuffer(...).WriteTo(f) fails mid-write.","commonSituations":"TMPDIR pointing to a nonexistent or read-only directory, disk-full on /tmp, sandboxed/container environments with a read-only temp dir, or permissions issues on the kitty config/temp paths.","solutions":["Check TMPDIR / temp directory writability: echo test > $TMPDIR/x and remove it","Free disk space or point TMPDIR to a writable location with space","If running in a container/sandbox, mount a writable /tmp","Retry after fixing permissions on the temp dir"],"exampleFix":"# before\nTMPDIR=/nonexistent kitty +kitten icat img.png\n# after\nmkdir -p /tmp/kitty && TMPDIR=/tmp/kitty kitty +kitten icat img.png","handlingStrategy":"validation","validationCode":"import \"os\"\n\ntmp := os.TempDir()\nf, err := os.CreateTemp(tmp, \"probe\")\nif err != nil { /* fail early with a clear message */ }\nf.Close(); os.Remove(f.Name())","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep a writable, spacious TMPDIR","Monitor disk space on temp filesystems","In containers mount /tmp writable"],"tags":["icat","tempfile","disk-full","filesystem","kitty"],"backgroundTag":"temp-file-write-failed","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}