{"record":{"id":"2c678ad41d8af6ec","repo":"denoland/deno","slug":"brotli-compression-failed","errorCode":null,"errorMessage":"brotli compression failed","messagePattern":"brotli compression failed","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/web/compression.rs","lineNumber":107,"sourceCode":"    let mut output_offset = 0;\n    let mut total_out = Some(0);\n\n    loop {\n      let mut available_out = output.len() - output_offset;\n      let ok = self.stm.compress_stream(\n        operation,\n        &mut available_in,\n        input,\n        &mut input_offset,\n        &mut available_out,\n        &mut output,\n        &mut output_offset,\n        &mut total_out,\n        &mut |_, _, _, _| (),\n      );\n\n      if !ok {\n        return Err(CompressionError::IoTypeError(std::io::Error::new(\n          std::io::ErrorKind::InvalidData,\n          \"brotli compression failed\",\n        )));\n      }\n\n      let done = match operation {\n        BrotliEncoderOperation::BROTLI_OPERATION_FINISH => {\n          self.stm.is_finished()\n        }\n        _ => available_in == 0 && !self.stm.has_more_output(),\n      };\n\n      if done {\n        output.truncate(output_offset);\n        return Ok(output);\n      }\n\n      if output_offset == output.len() {","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/denoland/deno/blob/a961cdec3b1948844414ebeecc697dcad76df2d1/ext/web/compression.rs#L89-L125","documentation":"Deno's Web Streams CompressionStream implementation for the 'brotli' format: each write/flush runs through BrotliEncoderCompressStream, and if the native encoder returns failure (ok == false), the stream errors with ErrorKind::InvalidData and this message. Encoder failures are rare and usually indicate invalid stream state or memory pressure rather than bad input data.","triggerScenarios":"new CompressionStream('brotli') whose writer hits a native encoder failure during write(), flush(), or close() — e.g. corrupted encoder state after misuse of the stream, extremely large single-shot buffers, or a native brotli bug triggered by specific chunk boundaries.","commonSituations":"Server-side response compression pipelines built on CompressionStream('brotli'); piping very large files through a single write; version-specific encoder regressions; feeding the wrong format string ('br' instead of 'brotli' throws earlier, but near-misses confuse debugging).","solutions":["Confirm the format is exactly 'brotli' (not 'br', 'gzip', 'deflate', or 'deflate-raw').","Stream in modest chunks via pipeThrough(new CompressionStream('brotli')) instead of one huge write(), letting backpressure work.","Catch the stream error and fall back to identity or gzip/deflate compression so the response still ships.","Update Deno — native encoder fixes land in runtime updates."],"exampleFix":"// before\nconst out = await new Response(blob.pipeThrough(new CompressionStream(\"brotli\")).catch(() => blob)).arrayBuffer(); // unhandled mid-stream error\n\n// after\nasync function compressBrotli(blob) {\n  try {\n    return { body: blob.pipeThrough(new CompressionStream(\"brotli\")), encoding: \"br\" };\n  } catch {\n    return { body: blob, encoding: \"identity\" }; // graceful fallback\n  }\n}","handlingStrategy":"fallback","validationCode":"const VALID = new Set([\"gzip\", \"deflate\", \"deflate-raw\", \"brotli\"]);\nif (!VALID.has(format)) throw new Error(`CompressionStream format must be one of ${[...VALID]}, got ${format}`);","typeGuard":null,"tryCatchPattern":"try { return await compressWith(new CompressionStream(\"brotli\"), bytes); } catch (e) { if (/brotli compression failed/.test(String(e))) return bytes; /* identity fallback */ throw e; }","preventionTips":["Use pipeThrough with backpressure instead of single giant write() calls.","Keep runtime updated — native brotli encoder fixes ship with Deno releases.","Always ship an identity/gzip fallback path when compression is best-effort."],"tags":["compression","brotli","compressionstream","web-streams","web-api"],"backgroundTag":"compression-failed","analyzedSha":"a961cdec3b1948844414ebeecc697dcad76df2d1","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}