jdx/mise · error

invalid remote cache path component

Error message

invalid remote cache path component

What it means

cache_name extracts the final file-name component of a cache path for use as a store key. It fails with this message when the component is empty, '.', '..', or contains '/' or a NUL byte — none of which can be a single valid cache entry name. Callers use it in build_directory when assembling remote directory entries.

Source

Thrown at src/task/task_cache_store.rs:522

    }
    if path.components().any(|component| {
        matches!(
            component,
            Component::ParentDir | Component::RootDir | Component::Prefix(_)
        )
    }) {
        bail!("remote cache path escapes its output root");
    }
    Ok(())
}

fn cache_name(path: &Path) -> Result<String> {
    let name = path
        .file_name()
        .and_then(|name| name.to_str())
        .ok_or_else(|| eyre!("remote cache paths must be valid UTF-8"))?;
    if name.is_empty() || name == "." || name == ".." || name.contains(['/', '\0']) {
        bail!("invalid remote cache path component");
    }
    Ok(name.to_string())
}

fn validate_cache_name(name: &str) -> Result<()> {
    let path = Path::new(name);
    if name.is_empty()
        || name == "."
        || name == ".."
        || name.contains(['/', '\\', '\0'])
        || path.components().count() != 1
        || !matches!(path.components().next(), Some(Component::Normal(_)))
    {
        bail!("invalid remote cache path component");
    }
    Ok(())
}

View on GitHub (pinned to afd2eddd3a)

Solutions

  1. Ensure the path ends in a real file or directory name before calling build_directory.
  2. Sanitize the component: reject or replace '.', '..', '/', and NUL in the name before use.
  3. Log the offending path; if it comes from config, fix the configured value to a plain name.

Example fix

// before
let name = format!("outputs/{}");
// after
let name = component.to_string(); // single sanitized name, no separators
Defensive patterns

Strategy: validation

Validate before calling

fn is_valid_component(name: &str) -> bool {
    !name.is_empty() && name != "." && name != ".."
        && !name.contains(['/', '\0'])
}

Type guard

fn as_cache_component(p: &Path) -> Option<&str> {
    let n = p.file_name()?.to_str()?;
    is_valid_component(n).then_some(n)
}

Try / catch

match build_directory(&path) {
    Err(e) if e.to_string().contains("invalid remote cache path component") => {
        // log path and skip/sanitize the entry
    }
    r => r?,
}

Prevention

When it happens

Trigger: Calling cache_name (via build_directory) with a path whose file_name() is '.', '..', empty after conversion, or which itself embeds '/' or '\0' inside a single component name.

Common situations: Passing a directory path ending in '..' or '.', or hand-built names from environment/config values that were not sanitized.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


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