oven-sh/bun · error · HpackError

UnableToEncode

UnableToEncode

Error message

UnableToEncode

What it means

Sentinel variant of HpackError in the lshpack HTTP/2 HPACK binding: encoding a header into the HPACK dynamic table/byte stream failed (invalid header input or encoder state). Part of the FFI wrapper around lshpack; consumers match on the variant name.

Solutions

  1. Validate header names contain only legal token characters per RFC 7230
  2. Check the HPACK dynamic table state for corruption
  3. Reduce header sizes to fit within frame limits
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/http/lshpack.rs:49 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/af888c057157c6cf. Report an issue: GitHub.

Appendix: source

Thrown at src/http/lshpack.rs:49

pub struct DecodeResult {
    // TODO: lifetime — name/value point into an FFI thread_local shared buffer,
    // valid only until the next decode/encode call. Consider `DecodeResult<'a>`.
    pub name: &'static [u8],
    pub value: &'static [u8],
    pub never_index: bool,
    pub well_know: u16,
    /// offset of the next header position in src
    pub next: usize,
}

#[derive(thiserror::Error, strum::IntoStaticStr, Debug, Clone, Copy, PartialEq, Eq)]
pub enum HpackError {
    #[error("UnableToDecode")]
    UnableToDecode,
    #[error("EmptyHeaderName")]
    EmptyHeaderName,
    #[error("UnableToEncode")]
    UnableToEncode,
}

impl HPACK {
    /// DecodeResult name and value uses a thread_local shared buffer and should be copy/cloned before the next decode/encode call
    pub fn decode(&mut self, src: &[u8]) -> Result<DecodeResult, HpackError> {
        let mut header = lshpack_header::default();
        // SAFETY: genuine FFI — only the `(src.as_ptr(), src.len())` pair carries
        // an obligation here (in-bounds read), discharged by `src: &[u8]`. The
        // `self`/`output` preconditions are type-discharged via `&mut` in the
        // extern signature.
        let offset = unsafe { lshpack_wrapper_decode(self, src.as_ptr(), src.len(), &mut header) };
        if offset == 0 {
            return Err(HpackError::UnableToDecode);
        }
        if header.name_len == 0 {
            return Err(HpackError::EmptyHeaderName);
        }

View on GitHub (pinned to 8c5296ac45)