(
error: ExecFileException | null,
stdout: string,
stderr: string,
isRetry: boolean,
)
| 356 | |
| 357 | return new Promise((resolve, reject) => { |
| 358 | const handleResult = ( |
| 359 | error: ExecFileException | null, |
| 360 | stdout: string, |
| 361 | stderr: string, |
| 362 | isRetry: boolean, |
| 363 | ): void => { |
| 364 | // Success case |
| 365 | if (!error) { |
| 366 | resolve( |
| 367 | stdout |
| 368 | .trim() |
| 369 | .split('\n') |
| 370 | .map(line => line.replace(/\r$/, '')) |
| 371 | .filter(Boolean), |
| 372 | ) |
| 373 | return |
| 374 | } |
| 375 | |
| 376 | // Exit code 1 is normal "no matches" |
| 377 | if (error.code === 1) { |
| 378 | resolve([]) |
| 379 | return |
| 380 | } |
| 381 | |
| 382 | // Critical errors that indicate ripgrep is broken, not "no matches" |
| 383 | // These should be surfaced to the user rather than silently returning empty results |
| 384 | const CRITICAL_ERROR_CODES = ['ENOENT', 'EACCES', 'EPERM'] |
| 385 | if (CRITICAL_ERROR_CODES.includes(error.code as string)) { |
| 386 | reject(error) |
| 387 | return |
| 388 | } |
| 389 | |
| 390 | // If we hit EAGAIN and haven't retried yet, retry with single-threaded mode |
| 391 | // Note: We only use -j 1 for this specific retry, not for future calls. |
| 392 | // Persisting single-threaded mode globally caused timeouts on large repos |
| 393 | // where EAGAIN was just a transient startup error. |
| 394 | if (!isRetry && isEagainError(stderr)) { |
| 395 | logForDebugging( |
| 396 | `rg EAGAIN error detected, retrying with single-threaded mode (-j 1)`, |
| 397 | ) |
| 398 | logEvent('tengu_ripgrep_eagain_retry', {}) |
| 399 | ripGrepRaw( |
| 400 | args, |
| 401 | target, |
| 402 | abortSignal, |
| 403 | (retryError, retryStdout, retryStderr) => { |
| 404 | handleResult(retryError, retryStdout, retryStderr, true) |
| 405 | }, |
| 406 | true, // Force single-threaded mode for this retry only |
| 407 | ) |
| 408 | return |
| 409 | } |
| 410 | |
| 411 | // For all other errors, try to return partial results if available |
| 412 | const hasOutput = stdout && stdout.trim().length > 0 |
| 413 | const isTimeout = |
| 414 | error.signal === 'SIGTERM' || |
| 415 | error.signal === 'SIGKILL' || |
no test coverage detected