nikivdev/code · error · anyhow::Error
failed to open {}
Error message
failed to open {} What it means
Raised by the Zed-open helper in src/deps.rs:1200 after spawning the Zed editor process successfully but with a non-zero exit status. The path could not be opened, and the tool reports the path that failed via `path.display()`. Distinct from the `failed to launch Zed` context error, which fires when the binary itself cannot be spawned.
Source
Thrown at src/deps.rs:1200
if let Ok(repo_ref) = repos::parse_github_repo(url) {
if root_path.join(repo_ref.owner).join(repo_ref.repo).exists() {
return true;
}
}
false
}
fn open_in_zed(path: &Path) -> Result<()> {
let status = Command::new("open")
.args(["-a", "/Applications/Zed.app"])
.arg(path)
.status()
.context("failed to launch Zed")?;
if status.success() {
Ok(())
} else {
bail!("failed to open {}", path.display());
}
}
fn path_relative(root: &Path, path: &Path) -> String {
path.strip_prefix(root)
.unwrap_or(path)
.display()
.to_string()
}
fn is_project_root(root: &Path, candidate: &Path) -> bool {
let root = root.canonicalize().unwrap_or_else(|_| root.to_path_buf());
let candidate = candidate
.canonicalize()
.unwrap_or_else(|_| candidate.to_path_buf());
root == candidate
}
View on GitHub (pinned to a747e741ae)
Solutions
- Verify the path exists and is readable: ls the exact path printed in the message
- Run `zed <path>` manually to see Zed's own error output
- Reinstall or repair the Zed CLI (`zed --version`) and ensure a display/GUI session is available
- Fall back to $EDITOR if Zed keeps failing
Example fix
// before f open deps/foo/src/lib.rs # path deleted by a rebuild error: failed to open deps/foo/src/lib.rs // after ls deps/foo/src/lib.rs && f open deps/foo/src/lib.rs
Defensive patterns
Strategy: fallback
Validate before calling
let target = Path::new(path);
if !target.exists() {
eprintln!("cannot open: {} does not exist", target.display());
return Ok(());
} Type guard
fn openable_in_editor(path: &Path) -> bool {
path.exists() && std::fs::metadata(path).map(|m| !m.is_dir() || path.is_dir()).is_ok()
} Try / catch
if let Err(e) = open_in_zed(path) {
let msg = e.to_string();
if msg.starts_with("failed to open") || msg.contains("failed to launch Zed") {
open_with_editor_env(path)?; // fallback to $EDITOR
} else { return Err(e); }
} Prevention
- Confirm the path exists right before opening (builds may delete/rename files)
- Set EDITOR as a reliable fallback
- Ensure a GUI session exists when using Zed on remote machines
- Verify `zed --version` works in the target environment
When it happens
Trigger: Calling the open-in-Zed action when Zed exits non-zero for the given path: e.g. the path does not exist or is not readable, Zed is not fully installed/licensed CLI handshake fails, or the user closes Zed with an error.
Common situations: Passing a file path that was deleted or renamed, running on a headless box with no display so Zed cannot start, or a stale `zed` shim on PATH pointing to an uninstall.
Related errors
- {app} exited with status {status}
- Lin.app is not running
- gen agent list failed
- gen agent list failed: {}
- Agent exited with status: {}
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/a9f5b7d085fdc37d.
Report an issue: GitHub.