dagger/dagger · error

invalid grep pattern %q: %w

Error message

invalid grep pattern %q: %w

What it means

renderReadLogs: compiling the requested grep pattern as a regex failed — the pattern is not valid regexp syntax.

Source

Thrown at core/mcp.go:2519

// renderReadLogs shapes captured log lines into a ReadLogs result: trims the
// last offset lines, applies the grep filter, numbers the lines, and caps the
// output. The error and empty cases carry the numbers an agent needs to
// recover — how many lines exist, how many were searched.
func renderReadLogs(spanID string, logs []string, offset, limit int, grepPattern string) (string, error) {
	if offset < 0 {
		offset = 0
	}
	// Trim the last offset lines
	if offset >= len(logs) {
		return "", fmt.Errorf("offset %d skips all %d available lines; retry with a smaller offset (0 reads the tail)", offset, len(logs))
	}
	logs = logs[:len(logs)-offset]

	// Apply grep filter if specified
	if grepPattern != "" {
		re, err := regexp.Compile(grepPattern)
		if err != nil {
			return "", fmt.Errorf("invalid grep pattern %q: %w", grepPattern, err)
		}
		var filteredLogs []string
		for i, line := range logs {
			if re.MatchString(line) {
				filteredLogs = append(filteredLogs, fmt.Sprintf("%6d→%s", i+1, line))
			}
		}
		if len(filteredLogs) == 0 {
			return fmt.Sprintf("(no matches for %q in the %d lines beneath span %s)", grepPattern, len(logs), spanID), nil
		}
		logs = filteredLogs
	} else {
		for i, line := range logs {
			logs[i] = fmt.Sprintf("%6d→%s", i+1, line)
		}
	}

	// Apply line limit if specified

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Fix the regex syntax named by the wrapped error
  2. Escape regex metacharacters to match literally
  3. Omit grep to read unfiltered
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at core/mcp.go:2519 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05). Data as JSON: /api/errors/21f90e70b3e6d321. Report an issue: GitHub.