jdx/mise · error
data too short to contain nonce
Error message
data too short to contain nonce
What it means
`decrypt_data` in the toolset env cache expects the encrypted blob to start with a 12-byte AES-GCM nonce followed by ciphertext. If the data is shorter than 12 bytes there cannot be a nonce, so it bails. This guards against corrupt, truncated, or plaintext cache files.
Solutions
- Delete the corrupted env cache file so the next run regenerates it.
- Re-run the mise command that failed; the cache rebuilds from live env resolution.
- Check disk space and filesystem health if truncation recurs.
- Ensure no other process is writing to the cache file concurrently.
Example fix
// before: corrupted cache rm ~/.cache/mise/env_cache.bin mise install // after: cache regenerated encrypted
Defensive patterns
Strategy: fallback
Validate before calling
if std::fs::metadata(cache_path).map(|m| m.len() < 12).unwrap_or(true) { std::fs::remove_file(cache_path).ok(); } Type guard
fn is_plausible_cache(data: &[u8]) -> bool { data.len() >= 12 } Try / catch
match env_cache::load(...) { Err(e) if e.to_string().contains("data too short") => { let _ = std::fs::remove_file(cache_path); recompute_env() }, other => other? } Prevention
- Treat cache files as disposable — always fall back to recomputing env.
- Don't redirect cache paths to arbitrary files.
- Monitor disk space to avoid truncated writes.
When it happens
Trigger: Calling `load` (or the test roundtrip) on cache bytes shorter than 12 bytes — e.g. an empty, truncated, or manually corrupted env cache file.
Common situations: Disk full causing truncated writes, a cache file partially overwritten or deleted-and-recreated, or pointing the cache path at a file that isn't an env cache.
Understand the failure class
Background: "Invalid JSON response" and "Failed to parse response" errors: when an API answers 200 but the body isn't the JSON your library expected — this error's family across 28 libraries.
Related errors
- cached failed digest verification
- cached is not canonical JSON
- watch file count mismatch
- action prediction payload is too large
- cache agent did not return the rustc identity
AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17).
Data as JSON: /api/errors/92d569f98d2f73e8.
Report an issue: GitHub.
Appendix: source
Thrown at src/toolset/env_cache.rs:43
}
fn encrypt_data(data: &[u8], key: &[u8; 32]) -> Result<Vec<u8>> {
let cipher = ChaCha20Poly1305::new_from_slice(key)
.map_err(|e| eyre::eyre!("failed to create cipher: {}", e))?;
let nonce = Nonce::generate();
let ciphertext = cipher
.encrypt(&nonce, data)
.map_err(|e| eyre::eyre!("encryption failed: {}", e))?;
// Format: nonce || ciphertext
let mut result = nonce.to_vec();
result.extend(ciphertext);
Ok(result)
}
fn decrypt_data(data: &[u8], key: &[u8; 32]) -> Result<Vec<u8>> {
if data.len() < 12 {
bail!("data too short to contain nonce");
}
let nonce =
Nonce::try_from(&data[..12]).map_err(|e| eyre::eyre!("failed to read nonce: {}", e))?;
let ciphertext = &data[12..];
let cipher = ChaCha20Poly1305::new_from_slice(key)
.map_err(|e| eyre::eyre!("failed to create cipher: {}", e))?;
let plaintext = cipher
.decrypt(&nonce, ciphertext)
.map_err(|e| eyre::eyre!("decryption failed: {}", e))?;
Ok(plaintext)
}
fn validate_watch_files(watch_files: &[PathBuf], expected_mtimes: &[u64]) -> Result<()> {
if watch_files.len() != expected_mtimes.len() {
bail!("watch file count mismatch");View on GitHub (pinned to 533346cc37)