{"record":{"id":"ad460beededbaf8a","repo":"gohugoio/hugo","slug":"webpencode-failed-d-s-n","errorCode":null,"errorMessage":"WebPEncode failed: %d (%s)\\n","messagePattern":"WebPEncode failed: (.+?) \\((.+?)\\)\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/warpc/genwebp/webp.c","lineNumber":133,"sourceCode":"    if (!WebPPictureInit(&pic))\n    {\n        fprintf(stderr, \"WebPPictureInit failed\\n\");\n        return NULL;\n    }\n\n    pic.use_argb = 1;\n    pic.width = width;\n    pic.height = height;\n    pic.writer = WebPMemoryWrite;\n    pic.custom_ptr = &wrt;\n    WebPMemoryWriterInit(&wrt);\n    ok = WebPPictureImportRGBA(&pic, rgba, stride);\n    if (ok)\n    {\n        ok = WebPEncode(config, &pic);\n        if (!ok)\n        {\n            fprintf(stderr, \"WebPEncode failed: %d (%s)\\n\", pic.error_code, kErrorMessages[pic.error_code]);\n        }\n    }\n    else\n    {\n        fprintf(stderr, \"WebPPictureImportRGBA failed: %d (%s)\\n\", pic.error_code, kErrorMessages[pic.error_code]);\n    }\n    WebPPictureFree(&pic);\n    if (!ok)\n    {\n        WebPMemoryWriterClear(&wrt);\n        return NULL;\n    }\n    *output_size = wrt.size;\n    return wrt.mem;\n}\n\nstatic uint8_t *encodeGray(WebPConfig *config, uint8_t *y, int width, int height, int stride, size_t *output_size)\n{","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/internal/warpc/genwebp/webp.c#L115-L151","documentation":"Printed by genwebp's encodeNRGBA (webp.c:133) when WebPEncode returns 0. The error_code on the WebPPicture is translated through kErrorMessages and printed alongside the numeric code. This is the umbrella failure for the actual VP8 encoding step; the most common codes are BAD_DIMENSION (width or height > 16383), OUT_OF_MEMORY, BITSTREAM_OUT_OF_MEMORY, INVALID_CONFIGURATION, or FILE_TOO_BIG (>4GB output). The function returns NULL and the Go host sees 'Error encoding NRGBA to WebP'.","triggerScenarios":"Encoding an image larger than 16383 pixels on either edge, encoding at very high quality/resolution that pushes the encoded output near 4GB, providing a WebPConfig with an invalid combination of fields (quality out of range, method > 6, lossless preset conflict), or running out of memory on a large frame.","commonSituations":"User uploads a huge source image (e.g. a 20000px panorama) and Hugo's resize still leaves a dimension over the WebP cap; very high `quality` setting combined with a large image; running in a memory-limited container; or a hint/compression preset that resolves to an invalid WebPConfig in initEncoderConfig.","solutions":["Cap input dimensions in the Go host before encoding: if width > 16383 || height > 16383, downscale first or skip WebP and fall back to another format.","Map the numeric error_code to its message (BAD_DIMENSION vs OUT_OF_MEMORY) to choose the right fix; the printed text tells you which.","Lower `quality` or `method` for very large frames to avoid FILE_TOO_BIG / OOM.","Validate WebPConfig fields before calling WebPEncode (quality 0-100, method 0-6, preset valid).","Raise the container/cgroup memory limit if the error is consistently OUT_OF_MEMORY on moderate images."],"exampleFix":"// before: WebPEncode failed BAD_DIMENSION on a 18000px source\nimg := load(path) // 18000 x 6000\nencodeWebp(img)\n\n// after: clamp to WebP's 16383 limit\nconst maxWH = 16383\nif img.Bounds().Dx() > maxWH || img.Bounds().Dy() > maxWH {\n    img = resizeKeepingAspect(img, maxWH)\n}\nencodeWebp(img)","handlingStrategy":"validation","validationCode":"// Reject images that exceed WebP's dimension cap before encoding.\nconst webpMaxDim = 16383\nfunc canEncodeWebp(w, h int) error {\n    if w <= 0 || h <= 0 { return fmt.Errorf(\"invalid dimensions %dx%d\", w, h) }\n    if w > webpMaxDim || h > webpMaxDim {\n        return fmt.Errorf(\"dimension %dx%d exceeds WebP cap %d\", w, h, webpMaxDim)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp or reject inputs with any dimension > 16383 before invoking the encoder.","Map the numeric error_code to its message to pick the correct remediation.","Lower quality/method for very large frames to avoid FILE_TOO_BIG / OOM.","Validate WebPConfig fields (quality 1-100, method 0-6) before encoding."],"tags":["webp","encoding","dimensions","oom","libwebp"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}