lima-vm/lima · error
failed to marshal instance %#q: %w
Error message
failed to marshal instance %#q: %w
What it means
filterInstances marshals each loaded Instance struct to JSON so a yq filter expression can be evaluated against it. json.Marshal fails only if the struct contains a value it cannot represent (unsupported type, cyclic reference); Lima throws this wrapped error from cmd/limactl/list.go:409 rather than silently dropping the instance. In practice this is an internal invariant failure — Instance is plain JSON-serializable data.
Source
Thrown at cmd/limactl/list.go:409
return bashCompleteInstanceNames(cmd)
}
// filterInstances applies yq expressions to instances and returns the filtered results.
func filterInstances(ctx context.Context, instances []*limatype.Instance, yqExprs []string) ([]*limatype.Instance, error) {
if len(yqExprs) == 0 {
return instances, nil
}
// the yq expression is evaluated with yqutil.EvaluateExpression, which disables environment variable access
// and file operations, mitigating injection attacks like ".name=strenv(SOME_SECRET_ENV)" which could
// trick Lima into exposing environment variables.
yqExpr := strings.Join(yqExprs, " | ")
var filteredInstances []*limatype.Instance
for _, instance := range instances {
jsonBytes, err := json.Marshal(instance)
if err != nil {
return nil, fmt.Errorf("failed to marshal instance %#q: %w", instance.Name, err)
}
result, err := yqutil.EvaluateExpression(ctx, yqExpr, jsonBytes)
if err != nil {
return nil, fmt.Errorf("failed to apply filter %#q: %w", yqExpr, err)
}
if len(bytes.TrimSpace(result)) > 0 {
filteredInstances = append(filteredInstances, instance)
}
}
return filteredInstances, nil
}
View on GitHub (pinned to dd909d0973)
Solutions
- Report the full wrapped error (the inner json.Marshal cause names the offending field) to lima-vm/lima
- Upgrade/downgrade limactl so the binary matches the instance data version on disk
- Delete the offending instance directory if it is stale and re-create the instance
Defensive patterns
Strategy: try-catch
Try / catch
jsonBytes, err := json.Marshal(instance)
if err != nil {
return fmt.Errorf("failed to marshal instance %#q: %w", instance.Name, err)
} Prevention
- Keep limactl binary and instance data from the same Lima version
- Don't add non-serializable fields (chan/func/cycles) when patching limatype.Instance
- Report occurrences upstream with the inner json error text
When it happens
Trigger: Running `limactl list --list-all` or a plain `limactl list` where filterInstances is invoked and json.Marshal(instance) returns an error for one of the loaded instances.
Common situations: Extremely rare for users; typically only appears with custom Lima builds, patched limatype.Instance fields containing unsupported types (channels, funcs, cycles), or corrupted in-memory state after version mismatches.
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
- instance %q not found
- disk format %#q not supported, use `qcow2` or `raw` instead
- failed to check if the autostart entry for instance %#q is r
- the YAML is invalid, attempted to save the buffer as %#q but
- the YAML is invalid, saved the buffer as %#q: %w
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/1316197728bdc995.
Report an issue: GitHub.