{"record":{"id":"9bad84baacf52066","repo":"astral-sh/ruff","slug":"failed-to-convert-path-to-url","errorCode":null,"errorMessage":"Failed to convert path to URL: {}","messagePattern":"Failed to convert path to URL: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_linter/src/message/sarif.rs","lineNumber":390,"sourceCode":"            },\n            replacements,\n        }];\n\n        Some(SarifFix {\n            description: RuleDescription {\n                text: fix_description,\n            },\n            artifact_changes,\n        })\n    }\n\n    #[allow(clippy::unnecessary_wraps)]\n    fn uri(diagnostic: &Diagnostic) -> Result<String> {\n        let path = normalize_path(&*diagnostic.expect_ruff_filename());\n        cfg_select! {\n            target_arch = \"wasm32\" => Ok(format!(\"file://{}\", path.display())),\n            _ => url::Url::from_file_path(&path)\n                .map_err(|()| anyhow::anyhow!(\"Failed to convert path to URL: {}\", path.display()))\n                .map(|url| url.to_string()),\n        }\n    }\n\n    fn from_message(\n        diagnostic: &'a Diagnostic,\n        config: &'a DisplayDiagnosticConfig,\n    ) -> Result<Self> {\n        let start_location = diagnostic.ruff_start_location().unwrap_or_default();\n        let end_location = diagnostic.ruff_end_location().unwrap_or_default();\n        let region = SarifRegion {\n            start_line: start_location.line,\n            start_column: start_location.column,\n            end_line: end_location.line,\n            end_column: end_location.column,\n        };\n\n        let uri = Self::uri(diagnostic)?;","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/astral-sh/ruff/blob/672bb4edf04c84f8b0753346359daee4057158f2/crates/ruff_linter/src/message/sarif.rs#L372-L408","documentation":"When emitting SARIF, each diagnostic's file path is converted to a `file://` URL with url::Url::from_file_path, which only accepts absolute paths; a relative path produces this error (wasm32 builds format the path directly and never hit it).","triggerScenarios":"`ruff check --output-format sarif` on a run where a diagnostic's filename is not absolute — notably linting stdin (`ruff check -` names the file `-`) or a relative `--stdin-filename` value.","commonSituations":"Editor integrations and scripts that pipe source via stdin and request SARIF; tools passing relative paths in unusual working directories.","solutions":["Give stdin an absolute name: `ruff check --stdin-filename \"$PWD/stdin.py\" - --output-format sarif`","Pass absolute file paths instead of relative ones","If the path cannot be made absolute, use a format that does not build file:// URLs (full, concise, json, json-lines)"],"exampleFix":"# before\nruff check --output-format sarif - < input.py\n\n# after\nruff check --stdin-filename \"$PWD/input.py\" --output-format sarif - < input.py","handlingStrategy":"validation","validationCode":"# absolutize inputs before invoking ruff\nf=$(realpath -- \"$f\")\nruff check --output-format sarif \"$f\"\n# for stdin, always pass an absolute --stdin-filename\nruff check --stdin-filename \"$PWD/stdin.py\" --output-format sarif -","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never run --output-format sarif on stdin without an absolute --stdin-filename","Pass absolute paths when invoking ruff from tools and wrappers","In integrations, join the workspace root with the relative path before calling ruff"],"tags":["sarif","paths","output-format"],"backgroundTag":null,"analyzedSha":"672bb4edf04c84f8b0753346359daee4057158f2","analyzedAt":"2026-08-16T08:54:05.464Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}