{"record":{"id":"fad11734fe6c4adc","repo":"gastownhall/beads","slug":"failed-to-save-config-w","errorCode":null,"errorMessage":"failed to save config: %w","messagePattern":"failed to save config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/doctor/fix/config_values.go","lineNumber":43,"sourceCode":"\n\tfixed := false\n\n\t// Fix database field: when backend is Dolt, database should be \"dolt\" not \"beads.db\"\n\tif cfg.GetBackend() == configfile.BackendDolt {\n\t\tif strings.HasSuffix(cfg.Database, \".db\") || strings.HasSuffix(cfg.Database, \".sqlite\") || strings.HasSuffix(cfg.Database, \".sqlite3\") {\n\t\t\tfmt.Printf(\"  Updating database: %q → %q (Dolt backend uses directory)\\n\", cfg.Database, \"dolt\")\n\t\t\tcfg.Database = \"dolt\"\n\t\t\tfixed = true\n\t\t}\n\t}\n\n\tif !fixed {\n\t\tfmt.Println(\"  → No configuration issues to fix\")\n\t\treturn nil\n\t}\n\n\tif err := cfg.Save(beadsDir); err != nil {\n\t\treturn fmt.Errorf(\"failed to save config: %w\", err)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":25,"sourceCodeEnd":48,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/doctor/fix/config_values.go#L25-L48","documentation":"ConfigValues wraps errors from cfg.Save(beadsDir) with this message. Save rewrites .beads/metadata.json after fixing the database field (e.g. \"beads.db\" → \"dolt\" for the Dolt backend); it fails when the file cannot be written — permissions, read-only filesystem, or disk errors.","triggerScenarios":"cfg.Save fails after ConfigValues detected and applied a fix: metadata.json is read-only, owned by another user, the filesystem is mounted read-only, or the disk is full.","commonSituations":"Running `bd doctor fix` under sudo (or without it) so file ownership mismatches afterwards; workspace on a read-only mount or in a container with a read-only layer; antivirus/backup tools holding the file open on Windows.","solutions":["Ensure the current user has write permission on .beads/metadata.json (ls -l .beads/metadata.json; chown/chmod as needed)","Do not mix sudo and non-sudo bd runs; fix ownership: sudo chown -R $USER .beads","Check the filesystem is not mounted read-only (mount | grep <path>) and remount read-write","Free disk space or close programs locking the file, then rerun the fix"],"exampleFix":"// shell\n$ bd doctor fix   # failed to save config: permission denied\n$ sudo chown -R $USER .beads && bd doctor fix","handlingStrategy":"validation","validationCode":"fi, err := os.Stat(filepath.Join(beadsDir, \"metadata.json\"))\nif err != nil { return err }\nif fi.Mode().Perm()&0o200 == 0 { return fmt.Errorf(\"metadata.json is not writable\") }\nif err := syscall.Access(filepath.Join(beadsDir, \"metadata.json\"), syscall.O_RDWR); err != nil {\n    return fmt.Errorf(\"no write access: %w\", err)\n}","typeGuard":"func metadataWritable(beadsDir string) bool {\n    return unix.Access(filepath.Join(beadsDir, \"metadata.json\"), unix.W_OK) == nil\n}","tryCatchPattern":"if err := fix.ConfigValues(path); err != nil {\n    if strings.HasPrefix(err.Error(), \"failed to save config\") {\n        // check permissions/read-only mount, fix, then retry\n    }\n    return err\n}","preventionTips":["Run bd consistently as one user; avoid sudo/no-sudo mixing","Confirm the workspace filesystem is mounted read-write","Check free disk space before fix operations","Watch for file locks from AV/backup tools on Windows"],"tags":["go","config","filesystem","permissions"],"backgroundTag":"config-save-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}