{"record":{"id":"0efb3ef98b874f7f","repo":"abiosoft/colima","slug":"error-marshalling-settings-to-json-w","errorCode":null,"errorMessage":"error marshalling settings to json: %w","messagePattern":"error marshalling settings to json: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"environment/vm/lima/config.go","lineNumber":42,"sourceCode":"\t_ = json.Unmarshal([]byte(b), &obj)\n\n\treturn obj\n}\nfunc (l limaVM) Get(key string) string {\n\tif val, ok := l.getConf()[key]; ok {\n\t\treturn val\n\t}\n\n\treturn \"\"\n}\n\nfunc (l limaVM) Set(key, value string) error {\n\tobj := l.getConf()\n\tobj[key] = value\n\n\tb, err := json.Marshal(obj)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error marshalling settings to json: %w\", err)\n\t}\n\n\tif err := l.Run(\"sudo\", \"mkdir\", \"-p\", filepath.Dir(configFile)); err != nil {\n\t\treturn fmt.Errorf(\"error saving settings: %w\", err)\n\t}\n\n\tif err := l.Write(configFile, b); err != nil {\n\t\treturn fmt.Errorf(\"error saving settings: %w\", err)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":24,"sourceCodeEnd":55,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/environment/vm/lima/config.go#L24-L55","documentation":"Returned by limaVM.Set when json.Marshal of the in-memory settings map (map[string]interface{} loaded from the VM-side config file) fails before persisting. Like the other marshal guards in this package it is defensive: a map decoded from JSON re-encodes cleanly unless it contains non-serializable injected values.","triggerScenarios":"Only if getConf() loaded/produced a map containing a json-incompatible value (chan/func/complex or a failing custom marshaler) — not producible from the JSON file itself; a corrupt or fork-modified codepath is the realistic source. Call sites are settings persistence (e.g. kubernetes runtime setConfig writing ConfigKey) during 'colima start'.","commonSituations":"Essentially never on stock builds; appears in forks that stuff arbitrary Go values into the settings map, or after tampering with the embedded config plumbing.","solutions":["If you maintain a fork, keep the settings map limited to JSON-native types (string, bool, float64, map, slice).","Reset persisted VM settings to reseed a clean map: delete the profile ('colima delete -f') and start again.","Upgrade colima if you hit this on a released binary and file an issue with the stack trace — it indicates an internal bug."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// keep the settings map JSON-native before marshalling\nfor k, v := range obj {\n    if !isJSONNative(v) { // string, bool, float64, map[string]interface{}, []interface{}, nil\n        return fmt.Errorf(\"settings key %q holds non-serializable value %T\", k, v)\n    }\n}","typeGuard":"func isJSONNative(v interface{}) bool {\n    switch v.(type) {\n    case nil, string, bool, float64, json.Number,\n         map[string]interface{}, []interface{}:\n        return true\n    }\n    return false\n}","tryCatchPattern":"b, err := json.Marshal(obj)\nif err != nil {\n    // defensive path: drop to a fresh map rather than failing the VM start\n    log.Warnln(fmt.Errorf(\"error marshalling settings to json: %w\", err))\n    b, _ = json.Marshal(map[string]string{key: value})\n}","preventionTips":["In forks, never insert chan/func/complex values into limaVM settings.","Round-trip test Set/GetConf in unit tests.","Treat this error as an internal bug signal on stock builds."],"tags":["json","serialization","settings","internal","lima"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}