{"record":{"id":"58b867b644e9b0f0","repo":"AlistGo/alist","slug":"failed-to-encode-thumbnail-w","errorCode":null,"errorMessage":"failed to encode thumbnail: %w","messagePattern":"failed to encode thumbnail: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"drivers/local/util.go","lineNumber":144,"sourceCode":"\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode image: %w\", err)\n\t}\n\n\tthumbImg := imaging.Resize(img, targetWidth, 0, imaging.Lanczos)\n\timg = nil\n\n\tvar buf bytes.Buffer\n\t// imaging.Encode\n\t// imaging.PNG, imaging.JPEG, imaging.GIF, imaging.BMP, imaging.TIFF\n\toutputFormat := imaging.JPEG\n\tencodeOptions := []imaging.EncodeOption{imaging.JPEGQuality(quality)}\n\n\t// outputFormat := imaging.PNG\n\t// encodeOptions := []imaging.EncodeOption{}\n\n\terr = imaging.Encode(&buf, thumbImg, outputFormat, encodeOptions...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to encode thumbnail: %w\", err)\n\t}\n\n\tthumbImg = nil\n\n\treturn &buf, nil\n}\n\n// Get the snapshot of the video\nfunc (d *Local) GetSnapshot(videoPath string) (imgData *bytes.Buffer, err error) {\n\tsanitized, err := sanitizeFilePath(videoPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid video path: %w\", err)\n\t}\n\tvideoPath = sanitized\n\n\t// Run ffprobe to get the video duration\n\tjsonOutput, err := ffmpeg.Probe(videoPath)\n\tif err != nil {","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/local/util.go#L126-L162","documentation":"imaging.Encode failed while writing the resized thumbnail as JPEG (with JPEGQuality(quality)) into an in-memory bytes.Buffer. Encoding to a bytes.Buffer almost never fails on I/O; the realistic causes are quality values outside 1-100 confusing the encoder, or an image with an alpha channel/odd dimensions producing an encode error in the underlying image/jpeg package.","triggerScenarios":"Calling the helper with quality <= 0 or > 100; resizing produced a zero-width image because targetWidth <= 0 and imaging.Resize returned a degenerate image; extremely large images exceeding memory during encode.","commonSituations":"Driver configuration exposing a 'thumbnail quality' field where 0 (unset int) slips through as an actual quality value instead of a default; custom builds that change the default thumb quality constant.","solutions":["Clamp quality to [1,100] with a sane default (e.g. 85) before calling the helper","Verify targetWidth > 0 before resizing","Inspect the wrapped error from image/jpeg — 'invalid quality' or memory errors point to the two cases above"],"exampleFix":"// before: quality passed through unvalidated\nencodeOptions := []imaging.EncodeOption{imaging.JPEGQuality(quality)}\n\n// after: clamp to a valid range\nif quality < 1 || quality > 100 {\n    quality = 85\n}\nencodeOptions := []imaging.EncodeOption{imaging.JPEGQuality(quality)}","handlingStrategy":"validation","validationCode":"func clampQuality(q int) int {\n    if q < 1 || q > 100 {\n        return 85\n    }\n    return q\n}","typeGuard":null,"tryCatchPattern":"Encode into bytes.Buffer failures are effectively bug indicators; log with the wrapped jpeg error and fall back to PNG encoding (imaging.PNG) which never fails on quality.","preventionTips":["Always clamp JPEG quality to 1-100 at the configuration boundary","Validate thumbnail width/quality settings in driver Init with clear config errors"],"tags":["image-encoding","jpeg","thumbnail","input-validation","local-driver"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}