{"record":{"id":"b3e4b1c4586ca003","repo":"abiosoft/colima","slug":"error-marshaling-store-w","errorCode":null,"errorMessage":"error marshaling store: %w","messagePattern":"error marshaling store: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"store/store.go","lineNumber":42,"sourceCode":"// Load loads the store from the json file.\nfunc Load() (s Store, err error) {\n\tb, err := os.ReadFile(storeFile())\n\tif err != nil {\n\t\treturn s, fmt.Errorf(\"cannot read store file: %w\", err)\n\t}\n\n\tif err := json.Unmarshal(b, &s); err != nil {\n\t\treturn s, fmt.Errorf(\"error unmarshaling store file: %w\", err)\n\t}\n\n\treturn s, nil\n}\n\n// save persists the store.\nfunc save(s Store) error {\n\tb, err := json.MarshalIndent(s, \"\", \"  \")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error marshaling store: %w\", err)\n\t}\n\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","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/store/store.go#L24-L60","documentation":"save() serializes the Store with json.MarshalIndent before writing it to disk; this error means that serialization failed. The Store is plain bool/string data, so in practice this is near-unreachable — hitting it indicates the Store type gained a JSON-unsupported member (chan, func, complex, cyclic reference) or a custom MarshalJSON that returns an error.","triggerScenarios":"A code change adds a channel/func field or cyclic pointer to Store and any store.Set persists; a custom MarshalJSON implementation returns an error for some state.","commonSituations":"Forks or contributions refactoring Store without a serialization round-trip test.","solutions":["Inspect the Store struct for fields json cannot encode (chan, func, complex, self-referencing pointers) and fix or tag them json:\"-\"","Add a unit test that round-trips Store through json.Marshal and back","If a custom MarshalJSON exists, exercise its error path"],"exampleFix":"// before\ntype Store struct {\n\tRamalamaProvisioned bool\n\tEvents chan struct{} // not JSON-serializable\n}\n\n// after\ntype Store struct {\n\tRamalamaProvisioned bool\n\tEvents chan struct{} `json:\"-\"` // excluded from serialization\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"var unsupported *json.UnsupportedTypeError\nif errors.As(err, &unsupported) {\n\t// a Store field type is not serializable: fix the struct — retrying will not help\n}","preventionTips":["Keep a serialization round-trip test for Store in CI","Never add chan/func fields to persisted structs without a json:\"-\" tag"],"tags":["serialization","json","go","internal"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}