Skip to content

Commit

Permalink
archive: report error from input stream
Browse files Browse the repository at this point in the history
if there is an error reading from the input stream, prefer to report
it instead of the error from the filter program itself.

We have a test in the buildah CI that expects the "no space left on
device" error that comes from the input stream, to avoid changing the
test, just fix it here.

Reported here: containers/buildah#5585

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed Jul 11, 2024
1 parent 573c558 commit 9883769
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/archive/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ func tryProcFilter(args []string, input io.Reader, cleanup func()) (io.ReadClose
go func() {
err := cmd.Run()
if err != nil && stderrBuf.Len() > 0 {
err = fmt.Errorf("%s: %w", strings.TrimRight(stderrBuf.String(), "\n"), err)
b := make([]byte, 0)
// if there is an error reading from input, prefer to return that error
_, errRead := input.Read(b)
if errRead != nil {
err = errRead
} else {
err = fmt.Errorf("%s: %w", strings.TrimRight(stderrBuf.String(), "\n"), err)
}
}
w.CloseWithError(err) // CloseWithErr(nil) == Close()
cleanup()
Expand Down

0 comments on commit 9883769

Please sign in to comment.