lima-vm/lima · error

failed to apply filter %#q: %w

Error message

failed to apply filter %#q: %w

What it means

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.

Source

Thrown at cmd/limactl/list.go:414

	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. Test the expression with the yq binary: `echo '{...}' | yq '<expr>'` to debug syntax
  2. Check yq documentation — Lima uses mikefarah/yq v4 syntax, not jq
  3. Quote shell-hostile characters in the expression (pipes, brackets, glob chars)
  4. Run `limactl list` without the filter to confirm the instance data itself loads

Example fix

// before
limactl list --filter '.status == "Running" &&'
// after (balanced expression, valid yq)
limactl list --filter '.status == "Running"'
Defensive patterns

Strategy: validation

Validate before calling

# verify expression with real yq before passing to limactl
echo '{"status":"Running"}' | yq '.status == "Running"' || echo "bad filter expr"

Type guard

func looksLikeYQExpr(expr string) bool {
	return strings.Count(expr, "(") == strings.Count(expr, ")") &&
		strings.Count(expr, "'")%2 == 0 && expr != ""
}

Try / catch

result, err := yqutil.EvaluateExpression(ctx, yqExpr, jsonBytes)
if err != nil {
	return fmt.Errorf("failed to apply filter %#q: %w", yqExpr, err)
}

Prevention

When it happens

Trigger: `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.

Common situations: 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).

Related errors


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