{"record":{"id":"da518402805dfc4c","repo":"lima-vm/lima","slug":"failed-to-apply-filter-q-w","errorCode":null,"errorMessage":"failed to apply filter %#q: %w","messagePattern":"failed to apply filter %#q: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/list.go","lineNumber":414,"sourceCode":"\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":396,"sourceCodeEnd":424,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/list.go#L396-L424","documentation":"When `limactl list` is given a filter expression (--go-template/yq-style filtering via --filter), each instance's JSON is passed to yqutil.EvaluateExpression. This error is returned when the yq expression itself fails to evaluate — syntax errors, invalid functions, or type mismatches in the expression — as opposed to an instance simply not matching the filter. Thrown at cmd/limactl/list.go:414.","triggerScenarios":"`limactl list --filter '<expr>'` (or programmatic filterInstances call) where the joined yq expression has bad syntax, references a nonexistent yq function, or applies an operator to an incompatible type.","commonSituations":"Typo in yq syntax (e.g. unbalanced parentheses/quotes); using jq syntax instead of yq (mikefarah yq) syntax; filtering on fields whose type differs from what the expression assumes (string vs number).","solutions":["Test the expression with the yq binary: `echo '{...}' | yq '<expr>'` to debug syntax","Check yq documentation — Lima uses mikefarah/yq v4 syntax, not jq","Quote shell-hostile characters in the expression (pipes, brackets, glob chars)","Run `limactl list` without the filter to confirm the instance data itself loads"],"exampleFix":"// before\nlimactl list --filter '.status == \"Running\" &&'\n// after (balanced expression, valid yq)\nlimactl list --filter '.status == \"Running\"'","handlingStrategy":"validation","validationCode":"# verify expression with real yq before passing to limactl\necho '{\"status\":\"Running\"}' | yq '.status == \"Running\"' || echo \"bad filter expr\"","typeGuard":"func looksLikeYQExpr(expr string) bool {\n\treturn strings.Count(expr, \"(\") == strings.Count(expr, \")\") &&\n\t\tstrings.Count(expr, \"'\")%2 == 0 && expr != \"\"\n}","tryCatchPattern":"result, err := yqutil.EvaluateExpression(ctx, yqExpr, jsonBytes)\nif err != nil {\n\treturn fmt.Errorf(\"failed to apply filter %#q: %w\", yqExpr, err)\n}","preventionTips":["Use mikefarah/yq v4 syntax, not jq syntax","Test the expression standalone with the yq CLI first","Quote expressions in shell to protect |, [, ], and quotes","Run `limactl list` unfiltered first to confirm instance data loads"],"tags":["cli","yq","filter"],"backgroundTag":"invalid-filter-expression","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}