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

  1. Report the full wrapped error (the inner json.Marshal cause names the offending field) to lima-vm/lima
  2. Upgrade/downgrade limactl so the binary matches the instance data version on disk
  3. 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

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


AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01). Data as JSON: /api/errors/1316197728bdc995. Report an issue: GitHub.