worker: move nil result check to more appropriate place

Result can be nil only when there's an error. Move the code to a place where
it makes more sense.
This commit is contained in:
Ondřej Budai 2020-06-27 15:46:25 +02:00
parent 66b80e0dac
commit 297dbe2fc7

View file

@ -243,6 +243,15 @@ func main() {
if osbuildError, ok := err.(*OSBuildError); ok {
result = osbuildError.Result
}
// Ensure we always have a non-nil result, composer doesn't like nils.
// This can happen in cases when OSBuild crashes and doesn't produce
// a meaningful output. E.g. when the machine runs of disk space.
if result == nil {
result = &common.ComposeResult{
Success: false,
}
}
} else {
log.Printf(" 🎉 Job completed successfully: %s", job.Id)
status = common.IBFinished
@ -251,15 +260,6 @@ func main() {
// signal to WatchJob() that it can stop watching
cancel()
// Ensure we always have a non-nil result, composer doesn't like nils.
// This can happen in cases when OSBuild crashes and doesn't produce
// a meaningful output. E.g. when the machine runs of disk space.
if result == nil {
result = &common.ComposeResult{
Success: false,
}
}
err = client.UpdateJob(job, status, result)
if err != nil {
log.Fatalf("Error reporting job result: %v", err)