osbuild-worker: handle error wrapping from dnfjson package
osbuild/images#751 wrapped the errors in the images/dnfjson package to provide more details, the depsolve job should take this into account to map the dnfjson error to the correct worker client error. This caused user input errors errors to be misclassified as internal errors, triggering depsolve job failure alerts.
This commit is contained in:
parent
6bb45ef9d1
commit
22a0452ea9
2 changed files with 12 additions and 6 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
|
@ -78,12 +79,12 @@ func workerClientErrorFrom(err error, logWithId *logrus.Entry) *clienterrors.Err
|
|||
logWithId.Errorf("workerClientErrorFrom expected an error to be processed. Not nil")
|
||||
}
|
||||
|
||||
switch e := err.(type) {
|
||||
case dnfjson.Error:
|
||||
var dnfjsonErr dnfjson.Error
|
||||
if errors.As(err, &dnfjsonErr) {
|
||||
// Error originates from dnf-json
|
||||
reason := fmt.Sprintf("DNF error occurred: %s", e.Kind)
|
||||
details := e.Reason
|
||||
switch e.Kind {
|
||||
reason := fmt.Sprintf("DNF error occurred: %s", dnfjsonErr.Kind)
|
||||
details := dnfjsonErr.Reason
|
||||
switch dnfjsonErr.Kind {
|
||||
case "DepsolveError":
|
||||
return clienterrors.New(clienterrors.ErrorDNFDepsolveError, reason, details)
|
||||
case "MarkingErrors":
|
||||
|
|
@ -96,7 +97,7 @@ func workerClientErrorFrom(err error, logWithId *logrus.Entry) *clienterrors.Err
|
|||
// by dnf-json and not explicitly handled here.
|
||||
return clienterrors.New(clienterrors.ErrorDNFOtherError, reason, details)
|
||||
}
|
||||
default:
|
||||
} else {
|
||||
reason := "rpmmd error in depsolve job"
|
||||
details := fmt.Sprintf("%v", err)
|
||||
// Error originates from internal/rpmmd, not from dnf-json
|
||||
|
|
|
|||
|
|
@ -26,6 +26,11 @@ func TestWorkerClientErrorFromDnfJson(t *testing.T) {
|
|||
entry, hook := makeMockEntry()
|
||||
clientErr := worker.WorkerClientErrorFrom(dnfJsonErr, entry)
|
||||
assert.Equal(t, `Code: 20, Reason: DNF error occurred: DepsolveError, Details: something is terribly wrong`, clientErr.String())
|
||||
|
||||
wrappedErr := fmt.Errorf("Wrap the error: %w", dnfJsonErr)
|
||||
clientErr = worker.WorkerClientErrorFrom(wrappedErr, entry)
|
||||
assert.Equal(t, `Code: 20, Reason: DNF error occurred: DepsolveError, Details: something is terribly wrong`, clientErr.String())
|
||||
|
||||
assert.Equal(t, 0, len(hook.AllEntries()))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue