BoundaryML/baml · error · FsPathError

native path is not absolute: {0}

Error message

native path is not absolute: {0}

What it means

FsPathError::NotAbsolute is returned by baml_path when a native filesystem path that must be absolute is instead relative. The VFS layer requires absolute native paths to unambiguously map between VFS URIs and on-disk locations.

Source

Thrown at baml_language/crates/baml_path/src/lib.rs:33

impl VfsPathBuf {
    pub fn new(path: String) -> Result<Self, FsPathError> {
        validate_vfs_path(&path)?;
        Ok(Self(path))
    }

    pub fn as_str(&self) -> &str {
        &self.0
    }

    pub fn into_string(self) -> String {
        self.0
    }
}

#[derive(Debug, thiserror::Error)]
pub enum FsPathError {
    #[error("native path is not absolute: {0}")]
    NotAbsolute(PathBuf),

    #[error("native path is not valid Unicode: {0:?}")]
    NonUnicode(PathBuf),

    #[error("unsupported native path prefix: {0}")]
    UnsupportedPrefix(PathBuf),

    #[error("invalid VFS path: {0}")]
    InvalidVfsPath(String),
}

impl From<FsPathError> for vfs::VfsError {
    fn from(error: FsPathError) -> Self {
        vfs::VfsError::from(vfs::error::VfsErrorKind::Other(error.to_string()))
    }
}

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Convert the path to absolute before use, e.g. std::fs::canonicalize(path) or std::env::current_dir()?.join(rel).
  2. Anchor user-supplied paths against an explicit project root at the boundary.
  3. Update stored config to hold absolute paths.
  4. Add a debug_assert!(p.is_absolute()) at call sites that require absolute input to fail early.

Example fix

// before
let vfs = FsPath::new("src/main.baml").to_vfs()?;

// after
let abs = std::env::current_dir()?.join("src/main.baml");
let vfs = FsPath::new(abs).to_vfs()?;
Defensive patterns

Strategy: validation

Validate before calling

fn ensure_absolute(p: &std::path::Path) -> bool { p.is_absolute() }
// call before conversion
if !ensure_absolute(&path) {
    let path = std::fs::canonicalize(&path)?;
}

Type guard

fn is_absolute_native(p: &std::path::Path) -> bool {
    p.is_absolute()
}

Prevention

When it happens

Trigger: Calling a baml_path conversion API (native->VFS mapping) with a relative path like "src/foo.baml" or one built from a relative working directory; passing a path captured before a chdir.

Common situations: Using std::env::current_dir() results carelessly; constructing paths from CLI args that were given relative; tests running with a different cwd than production; config files storing relative paths.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/36e9728c7a7e51cb. Report an issue: GitHub.