{"record":{"id":"b56bd67fb51e0874","repo":"gastownhall/beads","slug":"failed-to-write-user-config-yaml-w","errorCode":null,"errorMessage":"failed to write user config.yaml: %w","messagePattern":"failed to write user config\\.yaml: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/yaml_config.go","lineNumber":480,"sourceCode":"\t\treturn err\n\t}\n\tnormalizedKey := normalizeYamlKey(key)\n\n\tcontent, err := os.ReadFile(configPath) //nolint:gosec // configPath is a validated absolute user config path\n\tif err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\treturn nil\n\t\t}\n\t\treturn fmt.Errorf(\"failed to read user config.yaml: %w\", err)\n\t}\n\n\tnewContent := commentOutYamlKey(string(content), normalizedKey)\n\n\t// Preserve the owner-private 0600 posture every other user-global writer\n\t// uses (SetUserYamlConfig, setYamlConfigAtPath, the metrics bootstrap);\n\t// rewriting at 0644 would relax this shared user config to world-readable.\n\tif err := os.WriteFile(configPath, []byte(newContent), 0o600); err != nil { //nolint:gosec // configPath is from UserConfigYamlPath\n\t\treturn fmt.Errorf(\"failed to write user config.yaml: %w\", err)\n\t}\n\n\treturn nil\n}\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 {","sourceCodeStart":462,"sourceCodeEnd":498,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/config/yaml_config.go#L462-L498","documentation":"After reading and transforming the user config.yaml (commenting out the key), UnsetUserYamlConfig rewrites the file with os.WriteFile using 0600 to preserve the owner-private posture. Any write failure (permissions, read-only filesystem, disk full) is wrapped as 'failed to write user config.yaml'.","triggerScenarios":"os.WriteFile on the validated user config path fails: file or parent directory not writable by the current user, filesystem mounted read-only, immutable file attribute, or ENOSPC.","commonSituations":"Root-owned ~/.beads/config.yaml after a sudo run; disk quota exceeded; editing config on a read-only bind mount or CI workspace checked out read-only.","solutions":["Fix ownership/permissions: chown $USER ~/.beads/config.yaml && chmod 600 ~/.beads/config.yaml.","Ensure the filesystem is writable (remount rw, exit read-only CI workspace).","Check disk space/quota: df -h ~/.beads; free space and retry.","Inspect the wrapped %w cause for the exact OS error (EACCES, EROFS, ENOSPC) and address it."],"exampleFix":"// before\n-rw------- root root ~/.beads/config.yaml\nbd config unset metrics.enabled  // EACCES\n// after\nsudo chown $USER:$USER ~/.beads/config.yaml\nbd config unset metrics.enabled","handlingStrategy":"try-catch","validationCode":"dir := filepath.Dir(userConfigPath)\nif err := unix.Access(dir, unix.W_OK); err != nil {\n    return fmt.Errorf(\"cannot write %s: %w\", dir, err)\n}\nif fi, err := os.Stat(userConfigPath); err == nil && fi.Mode().Perm() != 0o600 {\n    os.Chmod(userConfigPath, 0o600)\n}","typeGuard":null,"tryCatchPattern":"err := config.UnsetUserYamlConfig(key)\nvar pe *fs.PathError\nif errors.As(err, &pe) {\n    switch {\n    case errors.Is(pe.Err, fs.ErrPermission): return fixOwnership(pe.Path)\n    case errors.Is(pe.Err, syscall.ENOSPC): return freeDiskAndRetry()\n    default: return pe\n    }\n}","preventionTips":["Run bd as the owning user; fix with chown after accidental sudo use.","Keep the user home on a writable, non-quota-exhausted filesystem.","Preserve 0600 mode when editing user config.yaml externally (e.g. umask 077).","Check disk space (df -h ~) when writes fail mysteriously."],"tags":["config","filesystem","permissions","write"],"backgroundTag":"config-write-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}