{"record":{"id":"7998eb9b7b875032","repo":"gastownhall/beads","slug":"failed-to-stat-user-config-yaml-w","errorCode":null,"errorMessage":"failed to stat user config.yaml: %w","messagePattern":"failed to stat user config\\.yaml: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/yaml_config.go","lineNumber":502,"sourceCode":"}\n\nfunc SetUserYamlConfig(key, value string) error {\n\tif err := validateYamlConfigValue(key, value); err != nil {\n\t\treturn err\n\t}\n\tconfigPath, err := UserConfigYamlPath()\n\tif err != nil {\n\t\treturn err\n\t}\n\tif err := os.MkdirAll(filepath.Dir(configPath), 0o755); err != nil {\n\t\treturn fmt.Errorf(\"failed to create user config directory: %w\", err)\n\t}\n\tif _, err := os.Stat(configPath); os.IsNotExist(err) {\n\t\tif err := os.WriteFile(configPath, []byte{}, 0o600); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to create user config.yaml: %w\", err)\n\t\t}\n\t} else if err != nil {\n\t\treturn fmt.Errorf(\"failed to stat user config.yaml: %w\", err)\n\t}\n\treturn setYamlConfigAtPath(configPath, key, value)\n}\n\nfunc setYamlConfigAtPath(configPath, key, value string) error {\n\n\t// Normalize key to canonical yaml format\n\tnormalizedKey := normalizeYamlKey(key)\n\n\t// Read existing config\n\tcontent, err := os.ReadFile(configPath) //nolint:gosec // configPath is from findProjectConfigYaml\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to read config.yaml: %w\", err)\n\t}\n\n\t// Update or add the key\n\tnewContent, err := updateYamlKey(string(content), normalizedKey, value)\n\tif err != nil {","sourceCodeStart":484,"sourceCodeEnd":520,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/config/yaml_config.go#L484-L520","documentation":"SetUserYamlConfig stats the user config.yaml to decide whether to create it or update it. When Stat fails with an error other than not-exist (permission denied on the parent, path is a directory, I/O error), the error is wrapped as 'failed to stat user config.yaml'.","triggerScenarios":"os.Stat(configPath) returns a non-IsNotExist error during SetUserYamlConfig: ~/.beads/config.yaml exists as a directory, parent directory lacks execute/search permission, or a filesystem I/O error occurs.","commonSituations":"Broken ~/.beads layout (config.yaml is a dir); permission drift after running bd under different users (sudo/root); failing disk or FUSE mount.","solutions":["Check what config.yaml is: if it is a directory, rename/remove it and let bd recreate the file.","Fix permissions on ~/.beads so the current user can traverse it (chmod u+rx ~/.beads, chown $USER).","Address the underlying OS error from the wrapped %w cause (EACCES, ENOTDIR, EIO).","If on a failing mount, move the home to healthy local storage by pointing HOME at a local writable dir."],"exampleFix":"// before\n$ file ~/.beads/config.yaml\n.beads/config.yaml: directory\nbd config set ... // stat fails ENOTDIR\n// after\nrm -rf ~/.beads/config.yaml\nbd config set metrics.enabled true   # recreated as file","handlingStrategy":"validation","validationCode":"fi, err := os.Lstat(userConfigPath)\nif err == nil && fi.IsDir() {\n    return fmt.Errorf(\"%s is a directory; remove it so bd can recreate config.yaml\", userConfigPath)\n}\nif err := unix.Access(filepath.Dir(userConfigPath), unix.W_OK); err != nil {\n    return fmt.Errorf(\"cannot access %s: %w\", filepath.Dir(userConfigPath), err)\n}","typeGuard":null,"tryCatchPattern":"err := config.SetUserYamlConfig(key, value)\nvar pe *fs.PathError\nif errors.As(err, &pe) && strings.Contains(err.Error(), \"failed to stat user config.yaml\") {\n    if fi, serr := os.Lstat(pe.Path); serr == nil && fi.IsDir() {\n        if rmErr := os.RemoveAll(pe.Path); rmErr != nil { return rmErr }\n        return config.SetUserYamlConfig(key, value)\n    }\n    return fmt.Errorf(\"fix permissions on %s: %w\", filepath.Dir(pe.Path), pe)\n}","preventionTips":["Keep config.yaml a regular file; investigate anything odd with `file`/`ls -la`.","Avoid switching users (sudo) for bd config operations on the same home.","Keep ~/.beads on healthy local storage, not failing FUSE/NFS mounts.","Check the wrapped errno (EACCES/ENOTDIR/EIO) to pick the right fix."],"tags":["config","filesystem","permissions","stat"],"backgroundTag":"stat-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}