{"record":{"id":"d1d5e98e185df5d2","repo":"plandex-ai/plandex","slug":"failed-to-get-image-tokens-for-s-v","errorCode":null,"errorMessage":"failed to get image tokens for %s: %v","messagePattern":"failed to get image tokens for (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/context_update.go","lineNumber":454,"sourceCode":"\n\t\t\t\t\t\tfilesSkippedAfterSizeLimit = append(filesSkippedAfterSizeLimit, ctx.FilePath)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\t// Accept\n\t\t\t\t\tmu.Lock()\n\t\t\t\t\ttotalSize += size\n\t\t\t\t\ttotalContextCount++\n\t\t\t\t\ttotalBodySize += (newBodySize - oldBodySize)\n\t\t\t\t\tmu.Unlock()\n\n\t\t\t\t\tvar numTokens int\n\t\t\t\t\tif shared.IsImageFile(ctx.FilePath) {\n\t\t\t\t\t\ttokens, err := shared.GetImageTokens(base64.StdEncoding.EncodeToString(fileContent), ctx.ImageDetail)\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\tmu.Lock()\n\t\t\t\t\t\t\tdefer mu.Unlock()\n\t\t\t\t\t\t\terrs = append(errs, fmt.Errorf(\"failed to get image tokens for %s: %v\", ctx.FilePath, err))\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnumTokens = tokens\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnumTokens = shared.GetNumTokensEstimate(string(fileContent))\n\t\t\t\t\t}\n\n\t\t\t\t\tmu.Lock()\n\t\t\t\t\tdefer mu.Unlock()\n\n\t\t\t\t\ttokenDiffsById[ctx.Id] = numTokens - ctx.NumTokens\n\t\t\t\t\tnumFiles++\n\t\t\t\t\tupdatedContexts = append(updatedContexts, ctx)\n\n\t\t\t\t\treqFns[ctx.Id] = func() (*shared.UpdateContextParams, error) {\n\t\t\t\t\t\treturn &shared.UpdateContextParams{\n\t\t\t\t\t\t\tBody: string(fileContent),\n\t\t\t\t\t\t}, nil","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/context_update.go#L436-L472","documentation":"Thrown when shared.GetImageTokens fails to compute the token cost of an image file that is part of a file-type context. The library uses this only when the file is classified as an image (IsImageFile) and its content changed, so tokenization of the base64 payload failed. The wrapped %v carries the decoder/model-limit error.","triggerScenarios":"A changed image file (SHA differs from ctx.Sha) is passed with its ImageDetail setting to shared.GetImageTokens, which returns an error — e.g. the bytes are not a valid image, the image exceeds the API's dimension/size limits, or the encoded payload is empty.","commonSituations":"Corrupt or truncated image committed to the repo; image format extension mismatch (e.g. .png containing WebP); image too large in pixels for the provider's vision API; invalid ImageDetail value stored on the context; zero-byte image files created by failed exports.","solutions":["Open/validate the image locally; re-export or replace the corrupted file.","Downscale the image so it fits the provider's max dimensions/size for vision tokens.","Verify the file extension matches the actual format (IsImageFile dispatches on extension).","If the file should not be treated as an image, rename it or remove it from context."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"f, err := os.Open(imgPath)\nif err != nil { return err }\n_, format, err := image.DecodeConfig(f)\nif err != nil { return fmt.Errorf(\"%s is not a decodable image: %w\", imgPath, err) }\nif format == \"\" || imgTooLargeForVision(format) { fix before adding to context }","typeGuard":"func isUsableImage(path string) bool {\n    f, err := os.Open(path)\n    if err != nil { return false }\n    defer f.Close()\n    _, _, err = image.DecodeConfig(f)\n    return err == nil\n}","tryCatchPattern":null,"preventionTips":["Validate images decode locally before adding them to context","Keep image dimensions within the provider's vision limits","Match file extensions to actual image formats","Watch for zero-byte images from failed exports"],"tags":["image","tokenization","vision"],"backgroundTag":"image-token-estimation-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}