{"record":{"id":"a81b208e546e8982","repo":"facebook/flow","slug":"not-an-absolute-filepath","errorCode":null,"errorMessage":"Not an absolute filepath - {}","messagePattern":"Not an absolute filepath - (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust_port/crates/flow_lsp/src/file_url.rs","lineNumber":100,"sourceCode":"        let drive_letter = caps.get(1).unwrap().as_str().to_ascii_uppercase();\n        let rest = caps.get(2).unwrap().as_str();\n        Ok(format!(\"{}:{}\", drive_letter, rest))\n    } else if !path.is_empty() && path.as_bytes()[0] == b'/' {\n        Err(format!(\"UNC file urls not supported - {}\", uri))\n    } else {\n        Ok(format!(\"/{}\", path))\n    }\n}\n\npub fn create(path: &str) -> String {\n    let absolute_path = if let Some(caps) = DOS_RE.captures(path) {\n        let drive_letter = caps.get(1).unwrap().as_str().to_ascii_lowercase();\n        let rest = caps.get(2).unwrap().as_str();\n        format!(\"{}:{}\", drive_letter, rest)\n    } else if let Some(rest) = path.strip_prefix('/') {\n        rest.to_string()\n    } else {\n        panic!(\"Not an absolute filepath - {}\", path);\n    };\n    format!(\"file:///{}\", encode(PATH_SAFE_CHARS, &absolute_path))\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]\n    fn test_valid_parse() {\n        let examples = [\n            (\"file://localhost/etc/fstab\", \"/etc/fstab\"),\n            (\"file:///etc/fstab\", \"/etc/fstab\"),\n            (\n                \"file://localhost/c:/WINDOWS/clock.avi\",\n                \"C:/WINDOWS/clock.avi\",\n            ),\n            (\"file:///c:/WINDOWS/clock.avi\", \"C:/WINDOWS/clock.avi\"),","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/facebook/flow/blob/f88ac94bcf6992f5d5a158854d94613ebb92c6e6/rust_port/crates/flow_lsp/src/file_url.rs#L82-L118","documentation":"file_url::create() only accepts absolute paths: it matches DOS drive paths like C:\\src via DOS_RE, strips a leading '/' from Unix absolute paths, and panics for everything else. The function has no way to resolve a relative path (there is no root parameter), so a relative input is treated as a programming error and aborts.","triggerScenarios":"Calling file_url::create(\"src/main.js\") or any string without a leading '/' or drive-letter prefix — typically an LSP integration that derives document paths from workspace-relative filenames, or tests passing relative fixtures.","commonSituations":"Editor/LSP clients that resolve documents against the workspace root but forget to absolutize; paths built by string concatenation that lose the leading slash; UNC Windows paths (\\\\server\\share\\...) which DOS_RE does not match; harnesses reusing fixture paths verbatim.","solutions":["Absolutize before calling create(): std::fs::canonicalize(path), or std::path::absolute(path) when the file may not exist yet, joined against the workspace root.","If the absolute prefix was merely lost, prepend '/'.","For UNC/Windows edge cases, map to a drive letter or extend DOS_RE in a local patch."],"exampleFix":"// before\nlet uri = file_url::create(\"src/index.js\"); // panics: relative\n\n// after\nlet abs = std::path::absolute(\"src/index.js\").unwrap();\nlet uri = file_url::create(&abs.to_string_lossy());","handlingStrategy":"type-guard","validationCode":"// absolutize against a known root before building the URI\nlet abs = std::path::absolute(path).map_err(|e| format!(\"cannot absolutize {path}: {e}\"))?;\nlet uri = file_url::create(&abs.to_string_lossy());","typeGuard":"fn is_supported_absolute_path(p: &str) -> bool {\n    if p.starts_with('/') {\n        return true;\n    }\n    let b = p.as_bytes();\n    b.len() >= 3\n        && b[0].is_ascii_alphabetic()\n        && b[1] == b':'\n        && (b[2] == b'/' || b[2] == b'\\\\')\n}","tryCatchPattern":null,"preventionTips":["Always resolve client-supplied paths against the workspace root before any URI conversion.","Prefer std::fs::canonicalize for existing files; it also normalizes '..' and symlinks.","Reject UNC paths (\\\\\\\\server\\\\share) early if your target only supports drive letters and Unix roots.","Unit-test the URI builder with relative, absolute, and drive-letter inputs."],"tags":["lsp","file-url","relative-path","paths","validation"],"backgroundTag":"path-must-be-absolute","analyzedSha":"f88ac94bcf6992f5d5a158854d94613ebb92c6e6","analyzedAt":"2026-08-20T10:41:37.992Z","contentChangedAt":"2026-08-20T10:41:37.992Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}