jdx/mise · error

could not get mtime for watch file

Error message

could not get mtime for watch file: {}

What it means

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.

Solutions

  1. Fix permissions on the watched file (chmod/chown) so it can be stat'ed.
  2. Remove the dangling symlink or restore the target file.
  3. Re-run the command; transient filesystem issues often resolve.
  4. Clear the cache and re-run if a particular entry keeps failing.

Example fix

// before
ls -l .env  # unreadable
sudo chown $(whoami) .env
// after
mise run dev  # validation succeeds
Defensive patterns

Strategy: try-catch

Validate before calling

if p.exists() && std::fs::metadata(p).is_err() { /* fix permissions or skip */ }

Try / catch

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? }

Prevention

When it happens

Trigger: 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.

Common situations: Files owned by another user with restrictive permissions, network filesystems with flaky stat, or TOCTOU races where the file is deleted mid-validation.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/2d2c3fe6e627a5e4. Report an issue: GitHub.

Appendix: source

Thrown at src/toolset/env_cache.rs:81

    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
                );
            }
        } else {
            bail!("could not get mtime for watch file: {}", path.display());
        }
    }
    Ok(())
}

/// Represents the cached environment data
#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) struct CachedEnv {
    /// Cached environment variables
    pub env: BTreeMap<String, String>,
    /// Variables explicitly removed by env directives
    #[serde(default)]
    pub env_remove: BTreeSet<String>,
    /// User-configured paths from env._.path directives
    pub user_paths: Vec<PathBuf>,
    /// Tool paths from installations
    pub tool_paths: Vec<PathBuf>,
    /// Time when the cache was created

View on GitHub (pinned to 533346cc37)