Skip to content

Commit

Permalink
fix: don't log non-errors as "Non-transient error: <nil>". Fixes #13881
Browse files Browse the repository at this point in the history
… (#13917)

Signed-off-by: Mason Malone <[email protected]>
  • Loading branch information
MasonM authored Nov 24, 2024
1 parent f2159dc commit 6b221f4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/e2e/signals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (s *SignalsSuite) TestSignaledContainerSet() {
Workflow("@testdata/signaled-container-set-workflow.yaml").
When().
SubmitWorkflow().
WaitForWorkflow().
WaitForWorkflow(killDuration).
Then().
ExpectWorkflow(func(t *testing.T, metadata *metav1.ObjectMeta, status *wfv1.WorkflowStatus) {
assert.Equal(t, wfv1.WorkflowFailed, status.Phase)
Expand Down
2 changes: 1 addition & 1 deletion util/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func IgnoreContainerNotFoundErr(err error) error {
// IsTransientErr reports whether the error is transient and logs it.
func IsTransientErr(err error) bool {
isTransient := IsTransientErrQuiet(err)
if !isTransient {
if err != nil && !isTransient {
log.Warnf("Non-transient error: %v", err)
}
return isTransient
Expand Down
9 changes: 9 additions & 0 deletions util/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"os/exec"
"testing"

log "github.com/sirupsen/logrus"
logtest "github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/assert"
apierr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -50,12 +52,19 @@ var (
const transientEnvVarKey = "TRANSIENT_ERROR_PATTERN"

func TestIsTransientErr(t *testing.T) {
hook := &logtest.Hook{}
log.AddHook(hook)
defer log.StandardLogger().ReplaceHooks(nil)

t.Run("Nil", func(t *testing.T) {
assert.False(t, IsTransientErr(nil))
assert.Nil(t, hook.LastEntry())
})
t.Run("ResourceQuotaConflictErr", func(t *testing.T) {
assert.False(t, IsTransientErr(apierr.NewConflict(schema.GroupResource{}, "", nil)))
assert.Contains(t, hook.LastEntry().Message, "Non-transient error:")
assert.True(t, IsTransientErr(apierr.NewConflict(schema.GroupResource{Group: "v1", Resource: "resourcequotas"}, "", nil)))
assert.Contains(t, hook.LastEntry().Message, "Transient error:")
})
t.Run("ResourceQuotaTimeoutErr", func(t *testing.T) {
assert.False(t, IsTransientErr(apierr.NewInternalError(errors.New(""))))
Expand Down

0 comments on commit 6b221f4

Please sign in to comment.