jaegertracing/jaeger · error

invalid pattern: %w

Error message

invalid pattern: %w

What it means

When GetServicesInput.Pattern is non-empty, the handler compiles it as a Go regular expression (regexp.Compile). If the pattern is not a valid regex, the handler wraps the compile error with "invalid pattern". This is pure client-input validation.

Source

Thrown at cmd/jaeger/internal/extension/jaegerquery/internal/mcptools/internal/handlers/get_services.go:57

}

// handle processes the get_services tool request.
func (h *getServicesHandler) handle(
	ctx context.Context,
	_ *mcp.CallToolRequest,
	input types.GetServicesInput,
) (*mcp.CallToolResult, types.GetServicesOutput, error) {
	// Get all services from storage
	services, err := h.queryService.GetServices(ctx)
	if err != nil {
		return nil, types.GetServicesOutput{}, fmt.Errorf("failed to get services: %w", err)
	}

	// Apply pattern filter if provided
	if input.Pattern != "" {
		re, err := regexp.Compile(input.Pattern)
		if err != nil {
			return nil, types.GetServicesOutput{}, fmt.Errorf("invalid pattern: %w", err)
		}

		filtered := make([]string, 0, len(services))
		for _, service := range services {
			if re.MatchString(service) {
				filtered = append(filtered, service)
			}
		}
		services = filtered
	}

	// Sort services for consistent ordering
	slices.Sort(services)

	// Apply limit, recording the pre-truncation total so the caller can detect
	// that results were cut (see issue #8901).
	limit := input.Limit
	if limit <= 0 {

View on GitHub (pinned to 806f444784)

Solutions

  1. Fix the pattern to be a valid Go/RE2 regular expression, e.g. "^payment.*$".
  2. Escape literal metacharacters (\., \*) if matching literal text.
  3. Replace glob wildcards: "pay*" becomes "^pay.*".
  4. Precompile/validate with regexp.Compile in the client before calling the tool.

Example fix

// before
input.Pattern = "*payment*"
// after
input.Pattern = ".*payment.*"
Defensive patterns

Strategy: validation

Validate before calling

func validPattern(p string) bool {
	if p == "" { return true }
	_, err := regexp.Compile(p)
	return err == nil
}
// usage: if !validPattern(input.Pattern) { input.Pattern = regexp.QuoteMeta(literal) }

Type guard

func compileSafe(p string) *regexp.Regexp {
	re, err := regexp.Compile(p)
	if err != nil { re = regexp.MustCompile(regexp.QuoteMeta(p)) }
	return re
}

Try / catch

out, _, err := handler.Handle(ctx, req, input)
if err != nil && strings.HasPrefix(err.Error(), "invalid pattern") {
	input.Pattern = regexp.QuoteMeta(input.Pattern) // treat as literal
	out, _, err = handler.Handle(ctx, req, input)
}

Prevention

When it happens

Trigger: Calling get_services with Pattern values like "(svc" (unbalanced parenthesis), "*prefix", "service[" (unclosed character class), or any RE2-unsupported construct such as a lookbehind "(?<=foo)".

Common situations: LLM-authored patterns with glob-style '*'/'?' instead of regex syntax; accidental shell metacharacter interpolation; patterns ported from PCRE tooling using lookarounds that Go RE2 rejects.

Related errors


AI-assisted analysis of jaegertracing/jaeger@806f444784 (2026-09-01). Data as JSON: /api/errors/7391d02f21770012. Report an issue: GitHub.