Skip to content

Commit

Permalink
fix(cli): Exit gracefully on broken pipe in search mode
Browse files Browse the repository at this point in the history
Noticed when running `srgn --go strings | less`, then aborting. A totally normal use case
  • Loading branch information
alexpovel committed Aug 18, 2024
1 parent 6268d17 commit d47b901
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -286,6 +286,12 @@ fn handle_actions_on_many_files_sorted(
Err(PathProcessingError::ApplicationError(
ApplicationError::NoneInScope | ApplicationError::SomeInScope,
)) => 0,
Err(PathProcessingError::IoError(e, _))
if e.kind() == io::ErrorKind::BrokenPipe && search_mode =>
{
trace!("Detected broken pipe, stopping search.");
break;
}
Err(
e @ (PathProcessingError::ApplicationError(ApplicationError::ActionError(
..,
@@ -396,6 +402,12 @@ fn handle_actions_on_many_files_threaded(
Err(PathProcessingError::ApplicationError(
ApplicationError::NoneInScope | ApplicationError::SomeInScope,
)) => WalkState::Continue,
Err(PathProcessingError::IoError(e, _))
if e.kind() == io::ErrorKind::BrokenPipe && search_mode =>
{
trace!("Detected broken pipe, stopping search.");
WalkState::Quit
}
Err(
e @ (PathProcessingError::ApplicationError(..)
| PathProcessingError::IoError(..)),

0 comments on commit d47b901

Please sign in to comment.