astral-sh/ruff · error

Could not diff paths

Error message

Could not diff paths

What it means

GitLab-format diagnostic rendering relativizes each path against the project root via pathdiff::diff_paths(&path, project_root).expect("Could not diff paths"). diff_paths returns None only when the paths have incompatible Windows prefixes (e.g. different drive letters), so the renderer panics in exactly that case.

Solutions

  1. Invoke ruff so files and project root share a drive; run from the same drive as the checked files
  2. Pass file arguments relative to the project root instead of cross-drive absolute paths
  3. If it still fires, report it - the renderer should fall back to the absolute path instead of panicking

Example fix

# before (panics: different drives)
ruff check --output-format gitlab D:\src\main.py  # run from C:\repo

# after (same drive, relative path)
cd D:\src && ruff check --output-format gitlab main.py
Defensive patterns

Strategy: validation

Validate before calling

// Windows tooling: ensure inputs share the project root's drive before rendering
const { root } = require('path').parse(projectRoot);
if (path.parse(file).root !== root) { useAbsolutePathInstead(); }

Prevention

When it happens

Trigger: Producing GitLab-format output where a diagnostic's file is on a different Windows drive than the project root - e.g. file D:\src\x.py with root C:\repo - so no relative path between them exists.

Common situations: Windows environments resolving dependencies or arguments across drives; UNC roots mixed with drive-letter paths; absolute cross-drive paths passed in include/files arguments.

Related errors


AI-assisted analysis of astral-sh/ruff@d1087a4b9e (2026-08-20). Data as JSON: /api/errors/4c8db99a47e3fe56. Report an issue: GitHub.

Appendix: source

Thrown at crates/ruff_db/src/diagnostic/render/gitlab.rs:180

}

/// Generate a unique fingerprint to identify a violation.
fn fingerprint(diagnostic: &Diagnostic, project_path: &str, salt: u64) -> u64 {
    let mut hasher = DefaultHasher::new();

    salt.hash(&mut hasher);
    diagnostic.name().hash(&mut hasher);
    project_path.hash(&mut hasher);

    hasher.finish()
}

/// Convert an absolute path to be relative to the specified project root.
fn relativize_path_to<P: AsRef<Path>, R: AsRef<Path>>(path: P, project_root: R) -> String {
    format!(
        "{}",
        pathdiff::diff_paths(&path, project_root)
            .expect("Could not diff paths")
            .display()
    )
}

#[cfg(test)]
mod tests {
    use crate::diagnostic::{
        DiagnosticFormat,
        render::tests::{create_diagnostics, create_syntax_error_diagnostics},
    };

    const FINGERPRINT_FILTERS: [(&str, &str); 1] = [(
        r#""fingerprint": "[a-z0-9]+","#,
        r#""fingerprint": "<redacted>","#,
    )];

    #[test]
    fn output() {

View on GitHub (pinned to d1087a4b9e)