Skip to content

Commit

Permalink
progress: do not return if osbuild status json reading fails
Browse files Browse the repository at this point in the history
This commit tweaks an issue that potentially an incorrect status
from osbuild would fail the build with a bad error message and
without us getting the full buildlog.
  • Loading branch information
mvo5 authored and supakeen committed Jan 27, 2025
1 parent 9c70379 commit 558be35
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 6 additions & 1 deletion bib/pkg/progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,12 @@ func runOSBuildWithProgress(pb ProgressBar, manifest []byte, store, outputDirect
}
wp.Close()

var statusErrs []error
for {
st, err := osbuildStatus.Status()
if err != nil {
return fmt.Errorf("error reading osbuild status: %w", err)
statusErrs = append(statusErrs, err)
continue
}
if st == nil {
break
Expand All @@ -392,6 +394,9 @@ func runOSBuildWithProgress(pb ProgressBar, manifest []byte, store, outputDirect
if err := cmd.Wait(); err != nil {
return fmt.Errorf("error running osbuild: %w\nOutput:\n%s", err, stdio.String())
}
if len(statusErrs) > 0 {
return fmt.Errorf("errors parsing osbuild status:\n%w", errors.Join(statusErrs...))
}

return nil
}
16 changes: 15 additions & 1 deletion bib/pkg/progress/progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func makeFakeOsbuild(t *testing.T, content string) string {
return p
}

func TestRunOSBuildWithProgress(t *testing.T) {
func TestRunOSBuildWithProgressErrorReporting(t *testing.T) {
restore := progress.MockOsbuildCmd(makeFakeOsbuild(t, `echo osbuild-stdout-output
>&2 echo osbuild-stderr-output
exit 112
Expand All @@ -156,3 +156,17 @@ osbuild-stdout-output
osbuild-stderr-output
`)
}

func TestRunOSBuildWithProgressIncorrectJSON(t *testing.T) {
restore := progress.MockOsbuildCmd(makeFakeOsbuild(t, `echo osbuild-stdout-output
>&2 echo osbuild-stderr-output
>&3 echo invalid-json
`))
defer restore()

pbar, err := progress.New("debug")
assert.NoError(t, err)
err = progress.RunOSBuild(pbar, []byte(`{"fake":"manifest"}`), "", "", nil, nil)
assert.EqualError(t, err, `errors parsing osbuild status:
cannot scan line "invalid-json": invalid character 'i' looking for beginning of value`)
}

0 comments on commit 558be35

Please sign in to comment.