Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

progress: fix missing build log output on errors in progress #820

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion bib/pkg/progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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...))
Expand Down
11 changes: 10 additions & 1 deletion bib/pkg/progress/progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package progress_test
import (
"bytes"
"fmt"
"io"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -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
`))
Expand All @@ -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
Expand Down
Loading