diff --git a/bib/pkg/progress/progress.go b/bib/pkg/progress/progress.go index 44f7da7..c7c79bb 100644 --- a/bib/pkg/progress/progress.go +++ b/bib/pkg/progress/progress.go @@ -368,6 +368,7 @@ func runOSBuildWithProgress(pb ProgressBar, manifest []byte, store, outputDirect } wp.Close() + var tracesMsgs []string var statusErrs []error for { st, err := osbuildStatus.Status() @@ -389,10 +390,18 @@ func runOSBuildWithProgress(pb ProgressBar, manifest []byte, store, outputDirect if st.Message != "" { pb.SetMessagef(st.Message) } + + // keep all messages/traces for better error reporting + if st.Message != "" { + tracesMsgs = append(tracesMsgs, st.Message) + } + if st.Trace != "" { + tracesMsgs = append(tracesMsgs, st.Trace) + } } if err := cmd.Wait(); err != nil { - return fmt.Errorf("error running osbuild: %w\nOutput:\n%s", err, stdio.String()) + return fmt.Errorf("error running osbuild: %w\nBuildLog:\n%s\nOutput:\n%s", err, strings.Join(tracesMsgs, "\n"), stdio.String()) } if len(statusErrs) > 0 { return fmt.Errorf("errors parsing osbuild status:\n%w", errors.Join(statusErrs...)) diff --git a/bib/pkg/progress/progress_test.go b/bib/pkg/progress/progress_test.go index 8bd2f93..4343c98 100644 --- a/bib/pkg/progress/progress_test.go +++ b/bib/pkg/progress/progress_test.go @@ -3,6 +3,7 @@ package progress_test import ( "bytes" "fmt" + "io" "os" "path/filepath" "reflect" @@ -141,7 +142,13 @@ func makeFakeOsbuild(t *testing.T, content string) string { } func TestRunOSBuildWithProgressErrorReporting(t *testing.T) { - restore := progress.MockOsbuildCmd(makeFakeOsbuild(t, `echo osbuild-stdout-output + restore := progress.MockOsStderr(io.Discard) + defer restore() + + restore = progress.MockOsbuildCmd(makeFakeOsbuild(t, ` +>&3 echo '{"message": "osbuild-stage-message"}' + +echo osbuild-stdout-output >&2 echo osbuild-stderr-output exit 112 `)) @@ -151,6 +158,8 @@ exit 112 assert.NoError(t, err) err = progress.RunOSBuild(pbar, []byte(`{"fake":"manifest"}`), "", "", nil, nil) assert.EqualError(t, err, `error running osbuild: exit status 112 +BuildLog: +osbuild-stage-message Output: osbuild-stdout-output osbuild-stderr-output