{"record":{"id":"1316197728bdc995","repo":"lima-vm/lima","slug":"failed-to-marshal-instance-q-w","errorCode":null,"errorMessage":"failed to marshal instance %#q: %w","messagePattern":"failed to marshal instance %#q: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/list.go","lineNumber":409,"sourceCode":"\treturn bashCompleteInstanceNames(cmd)\n}\n\n// filterInstances applies yq expressions to instances and returns the filtered results.\nfunc filterInstances(ctx context.Context, instances []*limatype.Instance, yqExprs []string) ([]*limatype.Instance, error) {\n\tif len(yqExprs) == 0 {\n\t\treturn instances, nil\n\t}\n\n\t// the yq expression is evaluated with yqutil.EvaluateExpression, which disables environment variable access\n\t// and file operations, mitigating injection attacks like \".name=strenv(SOME_SECRET_ENV)\" which could\n\t// trick Lima into exposing environment variables.\n\tyqExpr := strings.Join(yqExprs, \" | \")\n\n\tvar filteredInstances []*limatype.Instance\n\tfor _, instance := range instances {\n\t\tjsonBytes, err := json.Marshal(instance)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to marshal instance %#q: %w\", instance.Name, err)\n\t\t}\n\n\t\tresult, err := yqutil.EvaluateExpression(ctx, yqExpr, jsonBytes)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to apply filter %#q: %w\", yqExpr, err)\n\t\t}\n\n\t\tif len(bytes.TrimSpace(result)) > 0 {\n\t\t\tfilteredInstances = append(filteredInstances, instance)\n\t\t}\n\t}\n\n\treturn filteredInstances, nil\n}\n","sourceCodeStart":391,"sourceCodeEnd":424,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/list.go#L391-L424","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"jsonBytes, err := json.Marshal(instance)\nif err != nil {\n\treturn fmt.Errorf(\"failed to marshal instance %#q: %w\", instance.Name, err)\n}","preventionTips":["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"],"tags":["cli","json","internal"],"backgroundTag":"json-marshal-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}