Skip to content

Commit

Permalink
cmd/osbuild-worker/jobimpl-depsolve: show error.Reason only once
Browse files Browse the repository at this point in the history
as now the .Reason is properly passed over - it was printed twice
  • Loading branch information
schuellerf committed Jul 4, 2024
1 parent 7142437 commit 28aa517
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions cmd/osbuild-worker/jobimpl-depsolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,19 @@ func workerClientErrorFrom(err error) (*clienterrors.Error, error) {
switch e := err.(type) {
case dnfjson.Error:
// Error originates from dnf-json
reason := fmt.Sprintf("DNF error occurred: %s", e.Kind)
switch e.Kind {
case "DepsolveError":
return clienterrors.WorkerClientError(clienterrors.ErrorDNFDepsolveError, err.Error(), e.Reason), nil
return clienterrors.WorkerClientError(clienterrors.ErrorDNFDepsolveError, reason, e.Reason), nil
case "MarkingErrors":
return clienterrors.WorkerClientError(clienterrors.ErrorDNFMarkingErrors, err.Error(), e.Reason), nil
return clienterrors.WorkerClientError(clienterrors.ErrorDNFMarkingErrors, reason, e.Reason), nil
case "RepoError":
return clienterrors.WorkerClientError(clienterrors.ErrorDNFRepoError, err.Error(), e.Reason), nil
return clienterrors.WorkerClientError(clienterrors.ErrorDNFRepoError, reason, e.Reason), nil
default:
err := fmt.Errorf("Unhandled dnf-json error in depsolve job: %v", err)
// This still has the kind/reason format but a kind that's returned
// by dnf-json and not explicitly handled here.
return clienterrors.WorkerClientError(clienterrors.ErrorDNFOtherError, err.Error(), e.Reason), err
return clienterrors.WorkerClientError(clienterrors.ErrorDNFOtherError, reason, e.Reason), err
}
default:
err := fmt.Errorf("rpmmd error in depsolve job: %v", err)
Expand Down
6 changes: 3 additions & 3 deletions cmd/osbuild-worker/jobimpl-depsolve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestWorkerClientErrorFromDnfJson(t *testing.T) {
clientErr, err := worker.WorkerClientErrorFrom(dnfJsonErr)
assert.NoError(t, err)
// XXX: this is duplicating the details, see https://github.com/osbuild/images/issues/727
assert.Equal(t, clientErr.String(), `Code: 20, Reason: DNF error occurred: DepsolveError: something is terribly wrong, Details: something is terribly wrong`)
assert.Equal(t, `Code: 20, Reason: DNF error occurred: DepsolveError, Details: something is terribly wrong`, clientErr.String())
}

func TestWorkerClientErrorFromOtherError(t *testing.T) {
Expand All @@ -29,12 +29,12 @@ func TestWorkerClientErrorFromOtherError(t *testing.T) {
// assume that any "error" we get there is coming from rpmmd, can
// we generate a more typed error from dnfjson here for rpmmd errors?
assert.EqualError(t, err, "rpmmd error in depsolve job: some error")
assert.Equal(t, clientErr.String(), `Code: 23, Reason: rpmmd error in depsolve job: some error, Details: <nil>`)
assert.Equal(t, `Code: 23, Reason: rpmmd error in depsolve job: some error, Details: <nil>`, clientErr.String())
}

func TestWorkerClientErrorFromNil(t *testing.T) {
clientErr, err := worker.WorkerClientErrorFrom(nil)
// XXX: this is wrong, it should generate an internal error
assert.EqualError(t, err, "rpmmd error in depsolve job: <nil>")
assert.Equal(t, clientErr.String(), `Code: 23, Reason: rpmmd error in depsolve job: <nil>, Details: <nil>`)
assert.Equal(t, `Code: 23, Reason: rpmmd error in depsolve job: <nil>, Details: <nil>`, clientErr.String())
}

0 comments on commit 28aa517

Please sign in to comment.