{"record":{"id":"c0d62e1f24dc67bb","repo":"toeverything/AFFiNE","slug":"failed-to-encode-webp","errorCode":null,"errorMessage":"failed to encode webp","messagePattern":"failed to encode webp","errorType":"exception","errorClass":"napi::Error","httpStatus":null,"severity":"error","filePath":"packages/backend/native/src/image.rs","lineNumber":179,"sourceCode":"      .context(\"failed to decode image\")?,\n    _ => ImageReader::with_format(Cursor::new(input), format)\n      .into_decoder()\n      .context(\"failed to decode image\")?\n      .orientation()\n      .context(\"failed to decode image\")?,\n  })\n}\n\nfn encode_webp_lossy(image: &image::RgbaImage) -> AnyResult<Vec<u8>> {\n  let width = i32::try_from(image.width()).context(\"image width is too large\")?;\n  let height = i32::try_from(image.height()).context(\"image height is too large\")?;\n  let stride = width.checked_mul(4).context(\"image width is too large\")?;\n\n  let mut output = std::ptr::null_mut();\n  let encoded_len = unsafe { WebPEncodeRGBA(image.as_ptr(), width, height, stride, WEBP_QUALITY, &mut output) };\n\n  if output.is_null() || encoded_len == 0 {\n    bail!(\"failed to encode webp\");\n  }\n\n  let encoded = unsafe { std::slice::from_raw_parts(output, encoded_len) }.to_vec();\n  unsafe {\n    WebPFree(output.cast());\n  }\n\n  Ok(encoded)\n}\n\nfn preserve_exif(input: &[u8], format: ImageFormat, output: &mut Vec<u8>) -> AnyResult<()> {\n  let Some(file_type) = map_exif_file_type(format) else {\n    return Ok(());\n  };\n\n  let input = input.to_vec();\n  let Ok(mut metadata) = Metadata::new_from_vec(&input, file_type) else {\n    return Ok(());","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/backend/native/src/image.rs#L161-L197","documentation":"The libwebp lossy encoder (webp_encode wrapper) returned failure or produced a null buffer, so the RGBA image could not be encoded to WebP output bytes; process_image_inner surfaces this as an error to the JS caller.","triggerScenarios":"Raised when WebPEncodeRGBA returns a null pointer or zero length while encoding the resized RGBA image to lossy WebP.","commonSituations":"libwebp failed to encode the processed buffer, typically due to memory pressure or an invalid intermediate image. Retry or reduce the input size.","solutions":["Retry encoding; check the input image buffer is valid.","Reduce image size if the encoder runs out of memory."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}