gitbutlerapp/gitbutler · error
Cannot attempt to open anything but a directory: '{}'
Error message
Cannot attempt to open anything but a directory: '{}' What it means
Thrown by open_existing() in the gitbutler-tauri debug crate when the path passed to an 'open directory' helper exists on disk but is not a directory (a regular file, symlink to a file, or special file). The helper validates existence first, then requires is_dir() before handing the path to the OS opener/reveal logic. It exists to fail fast instead of letting the platform open() produce a confusing error.
Source
Thrown at crates/gitbutler-tauri/src/debug.rs:40
pub fn open_cache_folder() -> Result<(), Error> {
open_existing(but_path::app_cache_dir()?)
}
/// Open `dir` but refuse to do so if that would definitely fail as it's not a directory,
/// or it doesn't exist.
///
/// We can assume the directories exist.
fn open_existing(dir: impl AsRef<Path>) -> Result<(), Error> {
let dir = dir.as_ref();
if !dir.exists() {
return Err(anyhow!(
"Cannot attempt to open non-existing directory: '{}'",
dir.display()
)
.into());
}
if !dir.is_dir() {
return Err(anyhow!(
"Cannot attempt to open anything but a directory: '{}'",
dir.display()
)
.into());
}
let is_macos_stable_build =
cfg!(target_os = "macos") && matches!(AppChannel::new(), AppChannel::Release);
// On macOS stable builds, it would try to open `com.gitbutler.app` and treat it as application,
// which would fail. Instead, we reveal, which selects the directory in the finder and users
// can right-click it to see the package contents. Better than nothing.
// Maybe we can rename the application ID at some point.
if is_macos_stable_build {
reveal_directory(dir)
} else {
open::that(dir).map_err(anyhow::Error::from)
}
.with_context(|| format!("Failed to open directory at '{dir}'", dir = dir.display()))View on GitHub (pinned to caf1f223d3)
Solutions
- Verify the path points to a directory (ls -ld <path> or std::fs::metadata(path).is_dir()) and correct the caller to pass a directory.
- If the path is a file that should be a directory, move/delete the file and create the directory.
- If a symlink is involved, repoint it at a directory rather than a file.
- If you are a caller of open_existing(), pre-validate with the is_dir() check shown below instead of relying on the runtime error.
Example fix
// before
open_existing(&config.log_path)?; // panics/errors when log_path is a file
// after
let p = config.log_path.as_path();
if !p.is_dir() {
anyhow::bail!("log path '{}' is not a directory", p.display());
}
open_existing(&config.log_path)?; Defensive patterns
Strategy: validation
Validate before calling
use std::path::Path;
fn ensure_dir(p: &Path) -> anyhow::Result<()> {
let meta = std::fs::symlink_metadata(p)?;
if !meta.is_dir() {
anyhow::bail!("path '{}' is not a directory", p.display());
}
Ok(())
}
ensure_dir(&path)?;
open_existing(&path)?; Prevention
- Always resolve user-selected paths through is_dir() before passing to directory-opening helpers.
- When configurable, validate configured directories at settings-load time, not at use time.
- Resolve symlinks first so file-symlinks are caught early.
When it happens
Trigger: Calling a debug/API command that opens a folder (e.g. logs or app-data directory selection) with a path that resolves to a file; passing a symlink that points at a regular file; a stale path where a directory was replaced by a file of the same name.
Common situations: User picks a file instead of a folder in an 'Open Folder' dialog; a configured logs/cache path was recreated as a file by another tool; path typos that land on an existing file like 'logs.txt' instead of 'logs/'. On macOS the path may also be inside the com.gitbutler.app bundle which is specially handled just below this check.
Related errors
- When using OpenAI in a bring your own key configuration, you
- BUG: we do not create or work with symlinks
- Path does not exist: {path}
- Path is not a directory: {path}
- '{src}' is not a directory
AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20).
Data as JSON: /api/errors/39d03d7db4214e29.
Report an issue: GitHub.