{"record":{"id":"2d2c3fe6e627a5e4","repo":"jdx/mise","slug":"could-not-get-mtime-for-watch-file","errorCode":null,"errorMessage":"could not get mtime for watch file: {}","messagePattern":"could not get mtime for watch file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/toolset/env_cache.rs","lineNumber":81,"sourceCode":"    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            }\n        } else {\n            bail!(\"could not get mtime for watch file: {}\", path.display());\n        }\n    }\n    Ok(())\n}\n\n/// Represents the cached environment data\n#[derive(Debug, Clone, Serialize, Deserialize)]\npub(crate) struct CachedEnv {\n    /// Cached environment variables\n    pub env: BTreeMap<String, String>,\n    /// Variables explicitly removed by env directives\n    #[serde(default)]\n    pub env_remove: BTreeSet<String>,\n    /// User-configured paths from env._.path directives\n    pub user_paths: Vec<PathBuf>,\n    /// Tool paths from installations\n    pub tool_paths: Vec<PathBuf>,\n    /// Time when the cache was created","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/toolset/env_cache.rs#L63-L99","documentation":"After confirming a watched file exists, `validate_watch_files` calls `get_file_mtime`; if that returns None the mtime can't be determined and it bails. This prevents silently treating an unreadable file as unchanged and serving a possibly-wrong cached environment.","triggerScenarios":"Calling `load` where a watched file exists but `get_file_mtime` fails — e.g. permission errors stat'ing the file, a dangling symlink on some platforms, or the file vanishing in a race between exists() and the stat call.","commonSituations":"Files owned by another user with restrictive permissions, network filesystems with flaky stat, or TOCTOU races where the file is deleted mid-validation.","solutions":["Fix permissions on the watched file (chmod/chown) so it can be stat'ed.","Remove the dangling symlink or restore the target file.","Re-run the command; transient filesystem issues often resolve.","Clear the cache and re-run if a particular entry keeps failing."],"exampleFix":"// before\nls -l .env  # unreadable\nsudo chown $(whoami) .env\n// after\nmise run dev  # validation succeeds","handlingStrategy":"try-catch","validationCode":"if p.exists() && std::fs::metadata(p).is_err() { /* fix permissions or skip */ }","typeGuard":null,"tryCatchPattern":"match env_cache::load(...) { Err(e) if e.to_string().contains(\"could not get mtime\") => { log::warn!(\"cache validation degraded: {}\", e); recompute_env() }, other => other? }","preventionTips":["Ensure watched files are readable by the user running mise.","Avoid network filesystems for env-tracked files when possible.","Don't leave dangling symlinks in project directories."],"tags":["cache","filesystem","mtime"],"backgroundTag":"file-read-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"}