{"record":{"id":"61e2c5f1c9991a8c","repo":"jdx/mise","slug":"watch-file-count-mismatch","errorCode":null,"errorMessage":"watch file count mismatch","messagePattern":"watch file count mismatch","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/toolset/env_cache.rs","lineNumber":61,"sourceCode":"        bail!(\"data too short to contain nonce\");\n    }\n\n    let nonce =\n        Nonce::try_from(&data[..12]).map_err(|e| eyre::eyre!(\"failed to read nonce: {}\", e))?;\n    let ciphertext = &data[12..];\n\n    let cipher = ChaCha20Poly1305::new_from_slice(key)\n        .map_err(|e| eyre::eyre!(\"failed to create cipher: {}\", e))?;\n\n    let plaintext = cipher\n        .decrypt(&nonce, ciphertext)\n        .map_err(|e| eyre::eyre!(\"decryption failed: {}\", e))?;\n    Ok(plaintext)\n}\n\nfn validate_watch_files(watch_files: &[PathBuf], expected_mtimes: &[u64]) -> Result<()> {\n    if watch_files.len() != expected_mtimes.len() {\n        bail!(\"watch file count mismatch\");\n    }\n    for (path, expected_mtime) in watch_files.iter().zip(expected_mtimes.iter()) {\n        if !path.exists() {\n            // mtime=0 means file didn't exist when cached - skip if still doesn't exist\n            if *expected_mtime == 0 {\n                continue;\n            }\n            bail!(\"watch file no longer exists: {}\", path.display());\n        }\n        if let Some(current_mtime) = get_file_mtime(path) {\n            if current_mtime != *expected_mtime {\n                bail!(\n                    \"watch file mtime changed: {} (expected: {}, current: {})\",\n                    path.display(),\n                    expected_mtime,\n                    current_mtime\n                );\n            }","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/toolset/env_cache.rs#L43-L79","documentation":"`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.","triggerScenarios":"Calling `load` on an env-cache entry where `watch_files.len() != expected_mtimes.len()` — a hand-edited, partially written, or schema-drifted cache blob.","commonSituations":"Manual cache tampering, a version upgrade changing how the cache entry is serialized, or interrupted writes leaving a half-updated record.","solutions":["Clear the env cache so a fresh, consistent entry is written on next run.","Upgrade mise fully if old and new versions disagree on cache format.","Re-run the command; the cache is a performance layer, not required state.","Don't hand-edit cache files; regenerate them instead."],"exampleFix":"// before: inconsistent cache entry\nrm -rf ~/.cache/mise/env-cache\nmise run dev\n// after: cache rebuilt with matching lists","handlingStrategy":"fallback","validationCode":"if watch_files.len() != expected_mtimes.len() { std::fs::remove_file(cache_entry_path).ok(); }","typeGuard":"fn entry_consistent(w: &[PathBuf], m: &[u64]) -> bool { w.len() == m.len() }","tryCatchPattern":"match env_cache::load(...) { Err(e) if e.to_string().contains(\"count mismatch\") => recompute_env(), other => other? }","preventionTips":["Never hand-edit cache entries.","Upgrade all consumers of the cache format together.","Clear the cache after mise version upgrades."],"tags":["cache","corruption","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}