{"record":{"id":"bdd5a81b751693e0","repo":"lima-vm/lima","slug":"failed-to-marshal-instance-config-w","errorCode":null,"errorMessage":"failed to marshal instance config: %w","messagePattern":"failed to marshal instance config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/driverutil/vm.go","lineNumber":90,"sourceCode":"\tvar stderrBuf bytes.Buffer\n\tcmd.Stderr = &stderrBuf\n\n\tstdin, err := cmd.StdinPipe()\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tstdout, err := cmd.StdoutPipe()\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tif err := cmd.Start(); err != nil {\n\t\treturn \"\", err\n\t}\n\n\tencoder := json.NewEncoder(stdin)\n\tpayload, err := inst.MarshalJSON()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to marshal instance config: %w\", err)\n\t}\n\tif err := encoder.Encode(payload); err != nil {\n\t\treturn \"\", err\n\t}\n\tstdin.Close()\n\n\tdecoder := json.NewDecoder(stdout)\n\tvar response []byte\n\tif err := decoder.Decode(&response); err != nil {\n\t\treturn \"\", err\n\t}\n\n\tvar respInst limatype.Instance\n\tif err := respInst.UnmarshalJSON(response); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to unmarshal instance response: %w\", err)\n\t}\n\n\tif err := cmd.Wait(); err != nil {","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/driverutil/vm.go#L72-L108","documentation":"handleInspectStatusAction serializes the Instance with inst.MarshalJSON() to pipe it to the external driver's --inspect-status subcommand. This error means that custom JSON marshaling failed, which is rare and usually indicates an inconsistent in-memory Instance (e.g. a field that cannot be encoded, such as an invalid value in a custom marshaler).","triggerScenarios":"Calling InspectStatus on an external-driver instance where limatype.Instance.MarshalJSON returns an error — typically due to a field with a custom MarshalJSON that errors on the current instance state (invalid enum/URL/time value loaded from lima.yaml).","commonSituations":"Manually edited lima.yaml with a value the custom marshaler rejects (bad URL, out-of-range enum); programmatically constructed Instance missing required fields; a Lima version mismatch where the marshaler changed behavior.","solutions":["Look at the wrapped error to identify which field failed to marshal","Validate and fix the corresponding field in ~/.lima/<instance>/lima.yaml (URLs, enums, sizes)","Reload the instance through the standard load path so fields are normalized/defaulted","Report or upgrade if a Lima version regression in MarshalJSON is suspected; pin a working version"],"exampleFix":"// before: lima.yaml\nadditionalDisks: [\"disk:\"] // malformed\n// after\nadditionalDisks:\n  - name: \"data\"","handlingStrategy":"validation","validationCode":"if _, err := inst.MarshalJSON(); err != nil {\n    return fmt.Errorf(\"instance not marshalable, fix lima.yaml: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"status, err := driverutil.InspectStatus(ctx, inst)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to marshal instance config\") {\n        var jerr *json.UnsupportedTypeError\n        if errors.As(err, &jerr) {\n            log.Errorf(\"bad field: %v\", jerr.Value)\n        }\n    }\n    return err\n}","preventionTips":["Edit lima.yaml through `limactl edit` rather than by hand","Validate YAML fields (URLs, enums, sizes) before saving","Keep Instance construction via the loader so fields are normalized"],"tags":["json","serialization","external-driver"],"backgroundTag":"json-marshal-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}