{"record":{"id":"a0ce31972faf7576","repo":"gastownhall/beads","slug":"failed-to-inspect-target-repo-s-w","errorCode":null,"errorMessage":"failed to inspect target repo %s: %w","messagePattern":"failed to inspect target repo (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/create.go","lineNumber":990,"sourceCode":"\t\t\treturn nil, fmt.Errorf(\"failed to initialize remote cache: %w\", err)\n\t\t}\n\t\t// The dry-run parent lookup only reads from this cached remote store.\n\t\t// Do not add writes here; dry-runs must not mutate cached remotes.\n\t\tstore, err := cache.OpenStore(ctx, repoPath, newPreviewStoreFromConfig)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"dry-run parent lookup requires an existing cached remote store for %s: %w\", repoPath, err)\n\t\t}\n\t\treturn store, nil\n\t}\n\n\ttargetPath := routing.ExpandPath(repoPath)\n\tbeadsDir := filepath.Join(targetPath, \".beads\")\n\tmetadataPath := filepath.Join(beadsDir, \"metadata.json\")\n\tif _, err := os.Stat(metadataPath); err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\treturn nil, fmt.Errorf(\"target repo %s is not initialized; refusing to initialize it during dry-run\", targetPath)\n\t\t}\n\t\treturn nil, fmt.Errorf(\"failed to inspect target repo %s: %w\", targetPath, err)\n\t}\n\n\tstore, err := newPreviewStoreFromConfig(ctx, beadsDir)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open target store for dry-run: %w\", err)\n\t}\n\treturn store, nil\n}\n\n// isAmbiguousRepoTarget reports whether an explicit --repo value is a\n// bare/relative filesystem path (not absolute, not \"~/\"-prefixed). Such a\n// value silently resolves against the current working directory (see\n// routing.ExpandPath) rather than failing, so a misresolved value (e.g. a\n// typo) previously wrote a bead into a brand-new, disconnected database\n// instead of erroring (bd-8d3f).\nfunc isAmbiguousRepoTarget(repoFlagChanged bool, repoOverride string) bool {\n\treturn repoFlagChanged && !filepath.IsAbs(repoOverride) && !strings.HasPrefix(repoOverride, \"~/\")\n}","sourceCodeStart":972,"sourceCodeEnd":1008,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/create.go#L972-L1008","documentation":"This wraps a non-NotFound os.Stat error encountered while checking <repo>/.beads/metadata.json during a dry-run parent lookup. Unlike the not-initialized case, here the filesystem itself failed — permission denied, path is not traversable, I/O error — so the store's initialization state cannot even be determined. The wrapped %w carries the exact OS error.","triggerScenarios":"bd create --dry-run --repo <path> where os.Stat on <path>/.beads/metadata.json fails with an error other than ENOENT: permission denied on the repo or .beads directory, metadata.json exists but is unreadable due to mode bits, a component of the path is a file not a directory, or an I/O/filesystem error occurs.","commonSituations":"Running bd as a different user (or in CI) without read access to the checkout; .beads owned by root after a sudo run; metadata.json with restrictive permissions; macOS/Windows path or symlink problems; network-mounted filesystems with transient I/O errors.","solutions":["Fix filesystem permissions on the target repo and .beads/metadata.json (chmod/chown so the running user can stat/read them).","Read the wrapped OS error (%w) to identify whether it is EACCES, ENOTDIR, etc., and address that specific cause.","Verify no path component (repo dir or .beads) is actually a file or broken symlink; correct the layout.","If running under a different account (CI, sudo, container), run the dry-run as a user with access to the checkout.","Retry if the filesystem is network-mounted and the error indicates a transient I/O failure."],"exampleFix":"// before: metadata.json unreadable (owned by root)\nsudo bd init   # .beads now owned by root\nbd create --dry-run \"Task\" --repo .   // failed to inspect target repo ...\n// after: fix ownership/permissions, then retry\nsudo chown -R $(whoami) .beads\nbd create --dry-run \"Task\" --repo .","handlingStrategy":"validation","validationCode":"// Probe readability of the target's beads metadata before invoking bd.\nmetadataPath := filepath.Join(routing.ExpandPath(repoPath), \".beads\", \"metadata.json\")\nif f, err := os.Open(metadataPath); err != nil {\n    return fmt.Errorf(\"cannot read %s (check permissions/ownership): %w\", metadataPath, err)\n} else {\n    f.Close()\n}","typeGuard":null,"tryCatchPattern":"store, err := openDryRunTargetStore(ctx, repoPath)\nif err != nil {\n    if errors.Is(err, os.ErrPermission) {\n        fmt.Fprintf(os.Stderr, \"Permission denied inspecting target repo. Fix ownership of %s/.beads.\\n\", repoPath)\n        os.Exit(1)\n    }\n    return err\n}","preventionTips":["Avoid running bd with sudo; chown .beads back to your user if a privileged run changed ownership.","In CI, check out the repo with the same user that runs bd.","Keep .beads on a local (not flaky network-mounted) filesystem when possible.","Stat the metadata path in scripts before invoking bd dry-runs to fail fast with a clear message."],"tags":["filesystem","permissions","cli","dry-run"],"backgroundTag":"filesystem-permission-denied","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}