Skip to content

Commit 828fe5f

Browse files
committed
Filter: re-use original pipe, preserving any error status
1 parent 7e259fd commit 828fe5f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

script.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,13 +475,14 @@ func (p *Pipe) Filter(filter func(io.Reader, io.Writer) error) *Pipe {
475475
return p
476476
}
477477
pr, pw := io.Pipe()
478-
q := NewPipe().WithReader(pr)
478+
origReader := p.Reader
479+
p = p.WithReader(pr)
479480
go func() {
480481
defer pw.Close()
481-
err := filter(p, pw)
482-
q.SetError(err)
482+
err := filter(origReader, pw)
483+
p.SetError(err)
483484
}()
484-
return q
485+
return p
485486
}
486487

487488
// FilterLine sends the contents of the pipe to the function filter, a line at

0 commit comments

Comments
 (0)