{"record":{"id":"eeb983f595d07188","repo":"kovidgoyal/kitty","slug":"failed-to-decode-cached-image-metadata-w","errorCode":null,"errorMessage":"failed to decode cached image metadata: %w","messagePattern":"failed to decode cached image metadata: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kittens/choose_files/image_preview.go","lineNumber":98,"sourceCode":"func (p *ImagePreview) IsValidForColorScheme(bool) bool { return true }\nfunc (p *ImagePreview) IsReady() bool                   { return p.ready.Load() || p.render_channel == nil }\n\nfunc (p *ImagePreview) Unload() {\n\tp.source_img = nil\n}\n\nfunc load_image(cached_data map[string]string) (img *images.ImageData, err error) {\n\tfp := cached_data[IMAGE_METADATA_KEY]\n\tif fp == \"\" {\n\t\treturn nil, fmt.Errorf(\"missing cached image metadata\")\n\t}\n\tb, err := os.ReadFile(fp)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read cached image metadata: %w\", err)\n\t}\n\tvar m images.SerializableImageMetadata\n\tif err = json.Unmarshal(b, &m); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode cached image metadata: %w\", err)\n\t}\n\tframes := make([][]byte, len(m.Frames))\n\tfor i := range m.Frames {\n\t\tpath := cached_data[IMAGE_DATA_PREFIX+strconv.Itoa(i)]\n\t\tif path == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"missing cached data for frame: %d\", i)\n\t\t}\n\t\td, e := os.ReadFile(path)\n\t\tif e != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to read cached image frame %d data: %w\", i, e)\n\t\t}\n\t\tm.Frames[i].Size = len(d)\n\t\tframes[i] = d\n\t}\n\treturn images.ImageFromSerialized(m, frames)\n}\n\nfunc (p *ImagePreview) ensure_source_image() (err error) {","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kittens/choose_files/image_preview.go#L80-L116","documentation":"The cached image metadata file was read successfully but its contents are not valid JSON matching images.SerializableImageMetadata. This happens when the cache file was truncated (crash during write) or written by an incompatible kitty version with a different schema.","triggerScenarios":"json.Unmarshal of the cached metadata file fails inside load_image, invoked via RenderImagePreview or ensure_source_image.","commonSituations":"Kitty upgraded changing SerializableImageMetadata fields; partial write due to a killed kitten process; cache corruption.","solutions":["Invalidate the cache entry and re-render the image from the original file","Clear kitty's preview cache directory","Ensure all machines/instances sharing a cache run the same kitty version"],"exampleFix":"// before\nif err = json.Unmarshal(b, &m); err != nil { return nil, err }\n// after\nif err = json.Unmarshal(b, &m); err != nil {\n    os.Remove(fp) // invalidate corrupt cache\n    return nil, fmt.Errorf(\"corrupt cache, re-render needed: %w\", err)\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := json.Unmarshal(b, &m); err != nil { os.Remove(fp); re-render from source image }","preventionTips":["Write cache files atomically (temp file + rename) in your own similar code","Version-stamp cache formats so schema mismatches are detectable"],"tags":["kitty","json","cache-corruption","image-preview"],"backgroundTag":"json-deserialize-failed","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}