gastownhall/beads · error
failed to get current directory: %w
Error message
failed to get current directory: %w
What it means
`bd worktree info` needs the current working directory (via os.Getwd) to report worktree name/path/branch. If the OS cannot resolve the CWD, the command aborts with this error wrapping the underlying syscall error. This happens when the directory the shell is sitting in has been deleted or is otherwise unresolvable.
Source
Thrown at cmd/bd/worktree_cmd.go:378
)
}
func (err *worktreeRemovalPartialError) Unwrap() error {
return err.err
}
func runWorktreeInfo(cmd *cobra.Command, args []string) error {
evt := metrics.NewCommandEvent("worktree-info")
defer func() {
if c := metrics.Global(); c != nil {
c.CloseEventAndAdd(evt)
}
}()
ctx := context.Background()
cwd, err := os.Getwd()
if err != nil {
return fmt.Errorf("failed to get current directory: %w", err)
}
// Check if we're in a worktree (use RepoContext if available, fallback to git)
var isWorktree bool
rc, rcErr := beads.GetRepoContext()
if rcErr == nil {
isWorktree = rc.IsWorktree
} else {
isWorktree = git.IsWorktree()
}
if !isWorktree {
if jsonOutput {
result := map[string]interface{}{
"is_worktree": false,
}
encoder := json.NewEncoder(os.Stdout)
encoder.SetIndent("", " ")View on GitHub (pinned to 71377f2769)
Solutions
- cd to an existing directory (e.g. the main repo root) and rerun the command
- Verify the directory exists: pwd / ls the path; recreate the worktree if it was deleted
- If PATH_MAX is the cause, shorten the repository path (move repo closer to filesystem root)
Example fix
// before (shell) cd /repos/old-worktree && bd worktree info # directory deleted // after cd /repos/main && bd worktree info
Defensive patterns
Strategy: validation
Validate before calling
if cwd, err := os.Getwd(); err != nil {
// cd to a valid directory before running: bd worktree info
fmt.Println("working directory unresolvable; cd to repo root first")
} Try / catch
if _, err := os.Getwd(); err != nil {
return fmt.Errorf("cwd unavailable: %w", err)
}
// then run: bd worktree info Prevention
- Always run bd from an existing directory
- Recreate pruned worktrees before operating inside them
- Avoid extremely long repo paths near PATH_MAX
When it happens
Trigger: Running `bd worktree info` while the shell's working directory has been removed (e.g. a deleted worktree), or Getwd fails due to permission issues or PATH_MAX-length paths on some platforms.
Common situations: A git worktree was pruned/removed while the terminal was still cd'd into it; CI containers deleting the workspace before running bd; NFS/network mounts that have gone stale.
Related errors
- cannot pin git executable path: %w
- dolt path is not executable
- server: NewDoltServer: failed to determine absolute path of
- server: NewDoltServer: failed to determine absolute path of
- server: NewDoltServer: failed to determine absolute path of
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/137b9128f810f5e5.
Report an issue: GitHub.