target: extend TargetResult with TargetError

This will enable reporting of target-specific errors from jobs, once
they'll support multiple targets.

Target errors are currently reported via `JobResult.JobError`.
This commit is contained in:
Tomas Hozza 2022-06-13 15:56:42 +02:00 committed by Tom Gundersen
parent 59ded68457
commit 6f13db5b92

View file

@ -3,11 +3,14 @@ package target
import (
"encoding/json"
"fmt"
"github.com/osbuild/osbuild-composer/internal/worker/clienterrors"
)
type TargetResult struct {
Name TargetName `json:"name"`
Options TargetResultOptions `json:"options"`
TargetError *clienterrors.Error `json:"target_error,omitempty"`
}
func newTargetResult(name TargetName, options TargetResultOptions) *TargetResult {
@ -24,6 +27,7 @@ type TargetResultOptions interface {
type rawTargetResult struct {
Name TargetName `json:"name"`
Options json.RawMessage `json:"options"`
TargetError *clienterrors.Error `json:"target_error,omitempty"`
}
func (targetResult *TargetResult) UnmarshalJSON(data []byte) error {
@ -39,6 +43,7 @@ func (targetResult *TargetResult) UnmarshalJSON(data []byte) error {
targetResult.Name = rawTR.Name
targetResult.Options = options
targetResult.TargetError = rawTR.TargetError
return nil
}