jobimpl-osbuild: report a failed job on panic

Previously, the worker would happily report success if osbuild succeeded,
there was no JobError, but the job actually panicked in the meantime.
Let's fix this by adding a recovery mechanism.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
Ondřej Budai 2023-08-29 14:14:15 +02:00 committed by Ondřej Budai
parent 19e45b528f
commit d6eacad494
2 changed files with 10 additions and 0 deletions

View file

@ -280,6 +280,15 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
// In all cases it is necessary to report result back to osbuild-composer worker API.
defer func() {
if r := recover(); r != nil {
logWithId.Errorf("Recovered from panic: %v", r)
osbuildJobResult.JobError = clienterrors.WorkerClientError(
clienterrors.ErrorJobPanicked,
fmt.Sprintf("job panicked:\n%v\n\noriginal error:\n%v", r, osbuildJobResult.JobError),
nil,
)
}
validateResult(osbuildJobResult, job.Id().String())
err := job.Update(osbuildJobResult)

View file

@ -41,6 +41,7 @@ const (
ErrorOSTreeParamsInvalid ClientErrorCode = 34
ErrorOSTreeDependency ClientErrorCode = 35
ErrorRemoteFileResolution ClientErrorCode = 36
ErrorJobPanicked ClientErrorCode = 37
)
type ClientErrorCode int