facebook/flow · error

Not an absolute filepath - {}

Error message

Not an absolute filepath - {}

What it means

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.

Source

Thrown at rust_port/crates/flow_lsp/src/file_url.rs:100

        let drive_letter = caps.get(1).unwrap().as_str().to_ascii_uppercase();
        let rest = caps.get(2).unwrap().as_str();
        Ok(format!("{}:{}", drive_letter, rest))
    } else if !path.is_empty() && path.as_bytes()[0] == b'/' {
        Err(format!("UNC file urls not supported - {}", uri))
    } else {
        Ok(format!("/{}", path))
    }
}

pub fn create(path: &str) -> String {
    let absolute_path = if let Some(caps) = DOS_RE.captures(path) {
        let drive_letter = caps.get(1).unwrap().as_str().to_ascii_lowercase();
        let rest = caps.get(2).unwrap().as_str();
        format!("{}:{}", drive_letter, rest)
    } else if let Some(rest) = path.strip_prefix('/') {
        rest.to_string()
    } else {
        panic!("Not an absolute filepath - {}", path);
    };
    format!("file:///{}", encode(PATH_SAFE_CHARS, &absolute_path))
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_valid_parse() {
        let examples = [
            ("file://localhost/etc/fstab", "/etc/fstab"),
            ("file:///etc/fstab", "/etc/fstab"),
            (
                "file://localhost/c:/WINDOWS/clock.avi",
                "C:/WINDOWS/clock.avi",
            ),
            ("file:///c:/WINDOWS/clock.avi", "C:/WINDOWS/clock.avi"),

View on GitHub (pinned to f88ac94bcf)

Solutions

  1. 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.
  2. If the absolute prefix was merely lost, prepend '/'.
  3. For UNC/Windows edge cases, map to a drive letter or extend DOS_RE in a local patch.

Example fix

// before
let uri = file_url::create("src/index.js"); // panics: relative

// after
let abs = std::path::absolute("src/index.js").unwrap();
let uri = file_url::create(&abs.to_string_lossy());
Defensive patterns

Strategy: type-guard

Validate before calling

// absolutize against a known root before building the URI
let abs = std::path::absolute(path).map_err(|e| format!("cannot absolutize {path}: {e}"))?;
let uri = file_url::create(&abs.to_string_lossy());

Type guard

fn is_supported_absolute_path(p: &str) -> bool {
    if p.starts_with('/') {
        return true;
    }
    let b = p.as_bytes();
    b.len() >= 3
        && b[0].is_ascii_alphabetic()
        && b[1] == b':'
        && (b[2] == b'/' || b[2] == b'\\')
}

Prevention

When it happens

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

Common situations: 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.

Related errors


AI-assisted analysis of facebook/flow@f88ac94bcf (2026-08-20). Data as JSON: /api/errors/a81b208e546e8982. Report an issue: GitHub.