charmbracelet/crush · error
ripgrep: %w\n%s
Error message
ripgrep: %w\n%s
What it means
The ripgrep process exited with a failure after producing zero matches. Exit code 1 is treated as 'no matches' and returns nil; any other non-zero exit (or a non-ExitError failure) is reported here along with ripgrep's stderr output for diagnosis.
Source
Thrown at internal/agent/tools/glob.go:178
if err != nil {
break // EOF or read error; drain handled by Wait below.
}
if len(matches) >= candidatePool {
// Enough candidates; stop reading and let the process be
// killed by the command context / Wait. Draining the rest
// would just buffer paths we are going to discard.
break
}
}
// Close our end so ripgrep gets SIGPIPE and stops, then reap it.
_ = stdout.Close()
waitErr := cmd.Wait()
if waitErr != nil && len(matches) == 0 {
if ee, ok := waitErr.(*exec.ExitError); ok && ee.ExitCode() == 1 {
return nil, nil // No matches.
}
return nil, fmt.Errorf("ripgrep: %w\n%s", waitErr, stderr.String())
}
sort.SliceStable(matches, func(i, j int) bool {
return len(matches[i]) < len(matches[j])
})
if limit > 0 && len(matches) > limit {
matches = matches[:limit]
}
return matches, nil
}
func normalizeFilePaths(paths []string) {
for i, p := range paths {
paths[i] = filepath.ToSlash(p)
}
}
View on GitHub (pinned to 7944b8e522)
Solutions
- Read the stderr text appended to the error — it contains ripgrep's own diagnostic
- Validate the include/glob pattern and search path for typos
- Test the equivalent command manually (`rg --files --glob '<pattern>' <path>`) to reproduce
- Check RIPGREP_CONFIG_PATH for a user config injecting bad flags
Example fix
// before
waitErr := cmd.Wait()
if waitErr != nil && len(matches) == 0 {
if ee, ok := waitErr.(*exec.ExitError); ok && ee.ExitCode() == 1 {
return nil, nil
}
return nil, fmt.Errorf("ripgrep: %w\n%s", waitErr, stderr.String())
}
// after
waitErr := cmd.Wait()
if waitErr != nil && len(matches) == 0 {
var ee *exec.ExitError
if errors.As(waitErr, &ee) && ee.ExitCode() == 1 {
return nil, nil
}
return nil, fmt.Errorf("ripgrep: %w\n%s", waitErr, strings.TrimSpace(stderr.String()))
} Defensive patterns
Strategy: type-guard
Validate before calling
null
Type guard
var ee *exec.ExitError
if errors.As(waitErr, &ee) && ee.ExitCode() == 1 {
// no matches — not an error
} Try / catch
waitErr := cmd.Wait()
if waitErr != nil && len(matches) == 0 {
var ee *exec.ExitError
if errors.As(waitErr, &ee) && ee.ExitCode() == 1 {
return nil, nil
}
return nil, fmt.Errorf("ripgrep: %w\n%s", waitErr, stderr.String())
} Prevention
- Always read the appended stderr for ripgrep's own diagnostic
- Validate glob/regex patterns before passing to rg
- Reproduce with the raw rg command from the error to isolate bad flags
- Clear RIPGREP_CONFIG_PATH if a user config injects invalid flags
When it happens
Trigger: cmd.Wait() returns a waitErr that is not ExitError with code 1: ripgrep exit code 2 (regex parse error, invalid flag, unreadable path with strict mode), signal termination, or a non-ExitError Wait failure — and no matches were collected.
Common situations: Invalid glob include pattern passed to rg --glob, corrupted regex, ripgrep crashing (OOM/killed), searching a path rg cannot access, or stderr carrying config-file (RIPGREP_CONFIG_PATH) errors.
Related errors
- ripgrep: %w
- [Job %s] error executing command: %w
- ripgrep not found in $PATH
- invalid include pattern: %w
- %w: %s
AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29).
Data as JSON: /api/errors/b763f12f77094b2a.
Report an issue: GitHub.