gitbutlerapp/gitbutler · error

Failed to parse URL

Error message

Failed to parse URL

What it means

On Linux, show_in_finder opens directories in the file manager by converting the path to a file:// URL with Url::from_file_path and passing it to open_that. from_file_path only accepts absolute paths, so it returns Err for relative paths, and the code maps that to the bare message 'Failed to parse URL'.

Solutions

  1. Pass an absolute path: canonicalize with `std::fs::canonicalize(&path)` before calling show_in_finder.
  2. Check the caller that constructs the path and ensure it joins with the project root when the path is relative.
  3. Validate the path is non-empty and starts with '/' before invoking the API.
  4. If the path contains odd characters, confirm the value wasn't truncated or mangled upstream (e.g. by shell quoting).

Example fix

// before
show_in_finder("target/debug") // relative -> Failed to parse URL
// after
let abs = std::fs::canonicalize("target/debug")?;
show_in_finder(&abs.to_string_lossy()) // file:///.../target/debug
Defensive patterns

Strategy: validation

Validate before calling

import * as path from 'path';
if (!path.isAbsolute(dirPath) || dirPath.length === 0) {
  dirPath = path.resolve(dirPath); // make absolute before calling show_in_finder
}

Try / catch

try {
  await showInFinder(dirPath);
} catch (e) {
  if (String(e).includes('Failed to parse URL')) {
    showToast('Cannot open: path must be absolute. Re-resolving from project root...');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling show_in_finder on Linux with a directory path that is relative (does not start with '/') or otherwise not convertible to a file:// URL (e.g. contains invalid characters that percent-encoding cannot represent, or an empty string).

Common situations: Caller passes a path derived from a truncated/relative cwd; frontend sends a workspace-relative path instead of an absolute one; path string empty or containing NUL/unsupported bytes after serialization.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/3f945ad90cf6e5b7. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-api/src/open/mod.rs:630

            .with_context(|| format!("Failed to show '{path}' in Finder"))?;
    }

    #[cfg(target_os = "windows")]
    {
        use std::process::Command;
        Command::new("explorer")
            .arg("/select,")
            .arg(&path)
            .status()
            .with_context(|| format!("Failed to show '{path}' in Explorer"))?;
    }

    #[cfg(target_os = "linux")]
    {
        // For directories, open the directory directly
        if std::path::Path::new(&path).is_dir() {
            open_that(
                &Url::from_file_path(&path).map_err(|_| anyhow::anyhow!("Failed to parse URL"))?,
            )
            .with_context(|| format!("Failed to open directory '{path}' in file manager"))?;
        } else {
            // For files, try to open the parent directory
            if let Some(parent) = std::path::Path::new(&path).parent() {
                open_that(
                    &Url::from_file_path(parent)
                        .map_err(|_| anyhow::anyhow!("Failed to parse URL"))?,
                )
                .with_context(|| {
                    format!("Failed to open parent directory of '{path}' in file manager",)
                })?;
            } else {
                open_that(
                    &Url::from_file_path(&path)
                        .map_err(|_| anyhow::anyhow!("Failed to parse URL"))?,
                )
                .with_context(|| format!("Failed to open '{path}' in file manager"))?;

View on GitHub (pinned to 58e5313667)