gitbutlerapp/gitbutler · error
Path is not a directory
Error message
Path is not a directory: {path} What it means
Immediately after the existence check, the Windows branch requires the path to be a directory; if it exists but is a file, open_in_terminal() bails with this error. Terminals are launched with a working directory, so a file path is not a valid target.
Solutions
- Pass the project/repository root directory, not a file
- Derive the directory from the file path (e.g. path.parent()) before calling
- Check the caller that supplies the path to ensure it resolves to a directory
Example fix
// before
open_in_terminal("powershell", "C:\\repos\\proj\\README.md")
// after
open_in_terminal("powershell", "C:\\repos\\proj") Defensive patterns
Strategy: validation
Validate before calling
import { existsSync, statSync } from 'fs';
function isDirectory(p: string): boolean { return existsSync(p) && statSync(p).isDirectory(); } Type guard
fn is_dir(p: &str) -> bool { Path::new(p).is_dir() } Prevention
- Always pass the project root, never a file path
- Derive parent directories from file paths before invoking
- Validate path parameters at the API boundary
When it happens
Trigger: Calling open_in_terminal on Windows with a path to a regular file instead of a directory (e.g. a file selected instead of the project folder).
Common situations: UI passes the currently-open file instead of the project root, or a path stored from a file-picker that pointed at a file.
Related errors
- Path does not exist
- Automatic CLI installation is not supported on Windows. To…
- Cannot attempt to open anything but a directory
- Cannot attempt to open non-existing directory
- CLI destination must be absolute
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/637a53ec82434892.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-api/src/open/mod.rs:539
fn create_new_console(cmd: &mut Command) -> &mut Command {
use std::os::windows::process::CommandExt;
// CREATE_NEW_CONSOLE: Creates a new console for the process (0x00000010)
// This allows the terminal to run independently without blocking our thread
const CREATE_NEW_CONSOLE: u32 = 0x00000010;
cmd.creation_flags(CREATE_NEW_CONSOLE)
}
#[cfg(not(windows))]
fn create_new_console(cmd: &mut Command) -> &mut Command {
cmd
}
// Validate path exists and canonicalize it to proper Windows format
let path_buf = Path::new(&path);
if !path_buf.exists() {
bail!("Path does not exist: {path}");
}
if !path_buf.is_dir() {
bail!("Path is not a directory: {path}");
}
// Canonicalize to get the absolute, properly formatted Windows path
// This converts forward slashes to backslashes and resolves . and ..
let canonical_path = gix::path::realpath(path_buf)
.with_context(|| format!("Failed to canonicalize path: {path}"))?
.to_str()
.context("BUG: input path is String, should be able to convert back to it")?
.to_owned();
let canonical_path = &canonical_path;
// Check if the terminal binary exists in PATH before attempting to launch.
let binary_found = which::which(&terminal_id).is_ok();
if !binary_found {
return Err(anyhow::anyhow!("'{terminal_id}' was not found.")
.context(but_error::Code::DefaultTerminalNotFound));
}
View on GitHub (pinned to 58e5313667)