BoundaryML/baml · error · LspError

Path is invalid: {}: {message}

Error message

Path is invalid: {}: {message}

What it means

LspError::InvalidPath is raised when a supplied path exists as a string but cannot be converted into a valid filesystem path (e.g. contains illegal characters, fails to parse as a URI, or is otherwise malformed). The error includes both the offending path and a message explaining why it was rejected. It protects the server from operating on nonsense paths.

Source

Thrown at baml_language/crates/baml_lsp/src/error.rs:35

    #[error("Request not supported: {0}")]
    RequestNotSupported(String),
    #[error("Failed to serialize request result: {0}")]
    RequestSerializeError(serde_json::Error),
    /// The client's sink is gone; nothing more can be delivered.
    #[error("Client closed")]
    ClientClosed,
    /// Bounded transport backpressure (LSP `RequestFailed`, `-32803`).
    #[error("LSP outbound sink is saturated")]
    OutboundSaturated,
    /// A frame larger than the transport limit (LSP `RequestFailed`,
    /// `-32803`).
    #[error("LSP outbound frame exceeds the transport limit")]
    OutboundOversized,
    #[error("Invalid command arguments for command: {command}: {message}")]
    InvalidCommandArguments { command: String, message: String },
    #[error("File not found: {}", .0.display())]
    FileNotFound(PathBuf),
    #[error("Path is invalid: {}: {message}", path.display())]
    InvalidPath { path: PathBuf, message: String },
    /// The document's path is under no known source root.
    #[error("No source root contains {}", .0.display())]
    NoRootForPath(PathBuf),
    /// Cancellation claimed the response while the request was queued or
    /// running (LSP `RequestCanceled`, `-32800`).
    #[error("Request canceled: {0}")]
    RequestCanceled(String),
    /// The request's snapshot became stale under an applied source change
    /// (LSP `ContentModified`, `-32801`).
    #[error("Content modified: {0}")]
    ContentModified(String),
    /// A valid request that cannot be served right now (LSP `RequestFailed`,
    /// `-32803`).
    #[error("{0}")]
    RequestFailed(String),
    /// Violated invariants, panics, serialization (LSP `InternalError`,
    /// `-32603`).

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Print the path from the error and validate it parses as a proper file:// URI before sending requests.
  2. Percent-encode special characters (spaces, #, ?) in document URIs on the client side.
  3. Convert relative paths to absolute paths anchored at the workspace root before sending.
  4. Avoid sending virtual/unsupported URI schemes to requests that require real filesystem paths.

Example fix

// before
const uri = 'file:///my project/prompts#v2.baml';
// after
const uri = 'file:///my%20project/prompts%23v2.baml';
Defensive patterns

Strategy: validation

Validate before calling

function isValidFileUri(uri) {
  try {
    const u = new URL(uri);
    return u.protocol === 'file:' && !/\\/.test(u.pathname);
  } catch { return false; }
}

Try / catch

try {
  await request('textDocument/documentSymbol', { textDocument: { uri } });
} catch (e) {
  if (e.message?.startsWith('Path is invalid')) {
    console.warn('Unparseable path, skipping:', uri);
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: A document URI fails to parse into a PathBuf (invalid scheme, percent-encoding problems, non-UTF8 bytes); a path with illegal characters on the host OS is passed in a request; custom tooling sends relative or synthetic paths where an absolute file URI is required.

Common situations: Windows-style paths or backslashes sent from a client to a Unix-hosted server; unencoded spaces or '#'/'?' in URIs; virtual or in-memory document schemes (untitled:, memory:) passed where a real file path is required.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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