atuinsh/atuin · error

trailing bytes in encoded dotfiles var record. malformed

Error message

trailing bytes in encoded dotfiles var record. malformed

What it means

The dotfiles var record decoder reads a length-prefixed key string and then requires the payload to be fully consumed. If bytes remain after reading the key, the payload does not match the expected Delete-record layout, so it bails with this error. It protects against decoding malformed or mis-aligned binary payloads.

Solutions

  1. Delete/re-sync the affected var record so it is re-encoded correctly
  2. Verify encoder and decoder use the same layout (version byte, tag, length-prefixed strings)
  3. Check that the record tag matches (var records decoded with the var decoder, not kv/alias)

Example fix

// before: trust the payload blindly
let (key, bytes) = decode::read_str_from_slice(bytes)?;
// after: reject clearly mis-typed payloads early
let (tag, rest) = bytes.split_first().ok_or_else(|| eyre!("empty payload"))?;
if *tag != VAR_DELETE_TAG { return Err(eyre!("wrong record tag")); }
let (key, bytes) = decode::read_str_from_slice(rest)?;
Defensive patterns

Strategy: validation

Validate before calling

// Validate payload shape before decode: version byte + type byte + exactly one length-prefixed string
// fn plausible_var_delete(payload: &[u8]) -> bool {
//     decode::read_str_from_slice(&payload[2..]).map(|(_, rest)| rest.is_empty()).unwrap_or(false)
// }

Prevention

When it happens

Trigger: Deserializing a var record whose payload contains trailing bytes after the key string — corrupted payload, truncated/mangled encode, or a payload for a different record type fed to the Delete arm.

Common situations: Hand-edited or corrupted record payloads in the SQLite store; decode logic drift between encoder and decoder versions; accidentally passing KV or alias payloads to the var decoder.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of atuinsh/atuin@900007c480 (2026-09-19). Data as JSON: /api/errors/989d88f371e764a9. Report an issue: GitHub.

Appendix: source

Thrown at crates/atuin-dotfiles/src/store/var.rs:78

                match record_type {
                    // create
                    0 => {
                        let env = Var::deserialize(&mut bytes)?;
                        Ok(Self::Create(env))
                    }

                    // delete
                    1 => {
                        let nfields = decode::read_array_len(&mut bytes).map_err(error_report)?;
                        ensure!(nfields == 1, "too many entries in v0 dotfiles var delete record");

                        let bytes = bytes.remaining_slice();

                        let (key, bytes) =
                            decode::read_str_from_slice(bytes).map_err(error_report)?;

                        if !bytes.is_empty() {
                            bail!("trailing bytes in encoded dotfiles var record. malformed");
                        }

                        Ok(Self::Delete(key.to_owned()))
                    }

                    n => {
                        bail!("unknown Dotfiles var record type {n}");
                    }
                }
            }
            other => {
                bail!("unknown var record version {other:?}");
            }
        }
    }
}

#[derive(Debug, Clone)]

View on GitHub (pinned to 900007c480)