jdx/mise · error

watch file count mismatch

Error message

watch file count mismatch

What it means

`validate_watch_files` checks that the cached env entry's list of watched files and its list of expected mtimes are the same length before zipping them. A mismatch means the cache record itself is inconsistent/corrupt, so `load` rejects the cache entry instead of guessing which file maps to which mtime.

Solutions

  1. Clear the env cache so a fresh, consistent entry is written on next run.
  2. Upgrade mise fully if old and new versions disagree on cache format.
  3. Re-run the command; the cache is a performance layer, not required state.
  4. Don't hand-edit cache files; regenerate them instead.

Example fix

// before: inconsistent cache entry
rm -rf ~/.cache/mise/env-cache
mise run dev
// after: cache rebuilt with matching lists
Defensive patterns

Strategy: fallback

Validate before calling

if watch_files.len() != expected_mtimes.len() { std::fs::remove_file(cache_entry_path).ok(); }

Type guard

fn entry_consistent(w: &[PathBuf], m: &[u64]) -> bool { w.len() == m.len() }

Try / catch

match env_cache::load(...) { Err(e) if e.to_string().contains("count mismatch") => recompute_env(), other => other? }

Prevention

When it happens

Trigger: Calling `load` on an env-cache entry where `watch_files.len() != expected_mtimes.len()` — a hand-edited, partially written, or schema-drifted cache blob.

Common situations: Manual cache tampering, a version upgrade changing how the cache entry is serialized, or interrupted writes leaving a half-updated record.

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 jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/61e2c5f1c9991a8c. Report an issue: GitHub.

Appendix: source

Thrown at src/toolset/env_cache.rs:61

        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");
    }
    for (path, expected_mtime) in watch_files.iter().zip(expected_mtimes.iter()) {
        if !path.exists() {
            // mtime=0 means file didn't exist when cached - skip if still doesn't exist
            if *expected_mtime == 0 {
                continue;
            }
            bail!("watch file no longer exists: {}", path.display());
        }
        if let Some(current_mtime) = get_file_mtime(path) {
            if current_mtime != *expected_mtime {
                bail!(
                    "watch file mtime changed: {} (expected: {}, current: {})",
                    path.display(),
                    expected_mtime,
                    current_mtime
                );
            }

View on GitHub (pinned to 533346cc37)