lima-vm/lima · error
failed to marshal instance config: %w
Error message
failed to marshal instance config: %w
What it means
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).
Source
Thrown at pkg/driverutil/vm.go:90
var stderrBuf bytes.Buffer
cmd.Stderr = &stderrBuf
stdin, err := cmd.StdinPipe()
if err != nil {
return "", err
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return "", err
}
if err := cmd.Start(); err != nil {
return "", err
}
encoder := json.NewEncoder(stdin)
payload, err := inst.MarshalJSON()
if err != nil {
return "", fmt.Errorf("failed to marshal instance config: %w", err)
}
if err := encoder.Encode(payload); err != nil {
return "", err
}
stdin.Close()
decoder := json.NewDecoder(stdout)
var response []byte
if err := decoder.Decode(&response); err != nil {
return "", err
}
var respInst limatype.Instance
if err := respInst.UnmarshalJSON(response); err != nil {
return "", fmt.Errorf("failed to unmarshal instance response: %w", err)
}
if err := cmd.Wait(); err != nil {View on GitHub (pinned to dd909d0973)
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
Example fix
// before: lima.yaml additionalDisks: ["disk:"] // malformed // after additionalDisks: - name: "data"
Defensive patterns
Strategy: validation
Validate before calling
if _, err := inst.MarshalJSON(); err != nil {
return fmt.Errorf("instance not marshalable, fix lima.yaml: %w", err)
} Try / catch
status, err := driverutil.InspectStatus(ctx, inst)
if err != nil {
if strings.Contains(err.Error(), "failed to marshal instance config") {
var jerr *json.UnsupportedTypeError
if errors.As(err, &jerr) {
log.Errorf("bad field: %v", jerr.Value)
}
}
return err
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- failed to unmarshal instance response: %w
- failed to marshal as JSON: %+v: %w
- failed to marshal instance %#q: %w
- failed to write driver PID file: %w
- failed to create driver client: %w
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/bdd5a81b751693e0.
Report an issue: GitHub.