{"record":{"id":"1d2590fda3bd522a","repo":"abiosoft/colima","slug":"error-saving-store-w","errorCode":null,"errorMessage":"error saving store: %w","messagePattern":"error saving store: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"store/store.go","lineNumber":62,"sourceCode":"\n\tif err := os.WriteFile(storeFile(), b, 0o644); err != nil {\n\t\treturn fmt.Errorf(\"error writing store file: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// Set provides an easy way to set a value in the store.\nfunc Set(f func(*Store)) error {\n\ts, err := Load()\n\tif err != nil {\n\t\tlogrus.Debug(\"error loading store: %w\", err)\n\t}\n\n\tf(&s)\n\n\tif err := save(s); err != nil {\n\t\treturn fmt.Errorf(\"error saving store: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// Reset resets the values in the store to the defaults.\nfunc Reset() error {\n\t// first attempt to remove store file\n\tif err := os.Remove(storeFile()); err != nil {\n\t\t// if it fails\n\t\t// then attempt to set it to empty value\n\t\treturn Set(func(s *Store) { *s = Store{} })\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":44,"sourceCodeEnd":79,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/store/store.go#L44-L79","documentation":"store.Set wraps every failure of its trailing save() call. The surrounding code shapes this error: a Load failure is merely logged (via a malformed logrus.Debug call that misuses %w, which logrus does not expand) and Set continues with a possibly empty Store — so a corrupt store file is silently replaced with defaults before the write result is even known.","triggerScenarios":"Any store write under the marshal/write failure conditions (permissions, disk); additionally a corrupt existing store file whose Load error was swallowed, leaving Set to operate on an empty Store.","commonSituations":"Root-owned store files from sudo runs; corrupt store JSON after an interrupted write; full disks.","solutions":["Fix the underlying save failure first: permissions on the store dir, disk space","If the existing store file is corrupt, delete it so Load starts from defaults instead of the swallowed-error path","Patch Set to return the Load error instead of ignoring it (the logrus.Debug call is also malformed — it takes no format verbs)"],"exampleFix":"// before\ns, err := Load()\nif err != nil {\n\tlogrus.Debug(\"error loading store: %w\", err)\n}\nf(&s)\n\n// after\ns, err := Load()\nif err != nil {\n\treturn fmt.Errorf(\"error loading store: %w\", err)\n}\nf(&s)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := store.Set(func(s *store.Store) { s.Flag = true }); err != nil {\n\tif strings.Contains(err.Error(), \"error saving store\") {\n\t\t// persistence-layer failure: fix perms/disk; re-read state before retrying — the swallowed Load path may have reset it\n\t}\n}","preventionTips":["Keep the store file user-owned and backed up","Avoid sudo/non-sudo interleaving","After a Set failure, re-load state before retrying to detect the swallowed-Load reset"],"tags":["persistence","filesystem","bug","error-handling","go"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}