{"record":{"id":"9f16f552264264db","repo":"abiosoft/colima","slug":"error-encoding-kubernetes-config-to-json-w","errorCode":null,"errorMessage":"error encoding kubernetes config to json: %w","messagePattern":"error encoding kubernetes config to json: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"environment/container/kubernetes/kubernetes.go","lineNumber":86,"sourceCode":"\treturn c.guest.RunQuiet(\"sudo\", \"service\", \"k3s\", \"status\") == nil\n}\n\nfunc (c kubernetesRuntime) runtime() string {\n\treturn c.guest.Get(environment.ContainerRuntimeKey)\n}\n\nfunc (c kubernetesRuntime) config() config.Kubernetes {\n\tconf := config.Kubernetes{Version: DefaultVersion}\n\tif b := c.guest.Get(ConfigKey); b != \"\" {\n\t\t_ = json.Unmarshal([]byte(b), &conf)\n\t}\n\treturn conf\n}\n\nfunc (c kubernetesRuntime) setConfig(conf config.Kubernetes) error {\n\tb, err := json.Marshal(conf)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error encoding kubernetes config to json: %w\", err)\n\t}\n\n\treturn c.guest.Set(ConfigKey, string(b))\n}\n\nfunc (c *kubernetesRuntime) Provision(ctx context.Context) error {\n\tlog := c.Logger(ctx)\n\ta := c.Init(ctx)\n\tif c.Running(ctx) {\n\t\treturn nil\n\t}\n\n\tappConf, ok := ctx.Value(config.CtxKey()).(config.Config)\n\truntime := appConf.Runtime\n\tconf := appConf.Kubernetes\n\n\tif !ok {\n\t\t// this should be a restart/start while vm is active","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/environment/container/kubernetes/kubernetes.go#L68-L104","documentation":"Returned by kubernetesRuntime.setConfig when json.Marshal of the config.Kubernetes struct (version, type, k3s args etc.) fails before persisting it to the guest's config store via c.guest.Set(ConfigKey, ...). In practice this error is nearly unreachable: config.Kubernetes is a plain serializable struct of strings/bools, so the Go encoding/json package will not fail on it in shipped code.","triggerScenarios":"Only achievable if config.Kubernetes were extended with a json-incompatible field (chan, func, complex, or a MarshalJSON that errors), or if a value of a custom type errors at runtime; today it is defensive programming around json.Marshal. The realistic call path is any 'colima start --kubernetes --kubernetes-version ...' that writes runtime settings.","commonSituations":"Virtually none on released builds — if seen, it indicates a fork or custom build of colima with a broken Kubernetes settings struct, or memory corruption; treat as an internal invariant violation rather than an operational issue.","solutions":["If embedding/extending colima: audit any custom fields you added to config.Kubernetes for channels, funcs, or cyclic MarshalJSON.","Upgrade/repair your colima build — a stock binary cannot produce this from user input.","As a workaround, reset stored settings so a fresh config is written: 'colima delete --data kubernetes' (or 'colima delete -f' then 'colima start --kubernetes').","If you maintain a fork, add a unit test asserting json.Marshal(config.Kubernetes{}) never errors."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// if extending config.Kubernetes in a fork, assert serializability at startup\nif _, err := json.Marshal(config.Kubernetes{}); err != nil {\n    return fmt.Errorf(\"config.Kubernetes is not json-serializable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"b, err := json.Marshal(conf)\nif err != nil {\n    // unreachable in practice: fall back to defaults rather than failing the start\n    log.Warnln(fmt.Errorf(\"error encoding kubernetes config to json: %w\", err))\n    b, _ = json.Marshal(config.Kubernetes{Version: DefaultVersion})\n}","preventionTips":["Keep settings structs composed only of JSON-native types.","Add a unit test that round-trips json.Marshal/Unmarshal on every settings struct.","Report occurrences on stock builds upstream — they indicate a bug, not misconfiguration."],"tags":["kubernetes","json","serialization","internal"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}