progress: do not return if osbuild status json reading fails
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.
This commit is contained in:
parent
655b6bbd0f
commit
0e1a0f8ace
2 changed files with 21 additions and 2 deletions
|
|
@ -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
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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`)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue