diff --git a/hystrix/hystrix.go b/hystrix/hystrix.go index 8b4d68f..ecdfd23 100644 --- a/hystrix/hystrix.go +++ b/hystrix/hystrix.go @@ -290,7 +290,7 @@ func (c *command) tryFallback(ctx context.Context, err error) error { fallbackErr := c.fallback(ctx, err) if fallbackErr != nil { c.reportEvent("fallback-failure") - return fmt.Errorf("fallback failed with '%v'. run error was '%v'", fallbackErr, err) + return fmt.Errorf("fallback failed with '%v'. run error was '%w'", fallbackErr, err) } c.reportEvent("fallback-success") diff --git a/hystrix/hystrix_test.go b/hystrix/hystrix_test.go index 44f03ea..fcc3da2 100644 --- a/hystrix/hystrix_test.go +++ b/hystrix/hystrix_test.go @@ -2,6 +2,7 @@ package hystrix import ( "context" + "errors" "fmt" "testing" "time" @@ -215,6 +216,25 @@ func TestFailedFallback(t *testing.T) { }) } +func TestErrorTypeForTimeoutRunWithFailedFallback(t *testing.T) { + Convey("when your run function times out and fallback functions return an error", t, func() { + defer Flush() + ConfigureCommand("", CommandConfig{Timeout: 100}) + errChan := GoC(context.Background(), "", func(ctx context.Context) error { + time.Sleep(200 * time.Millisecond) + return nil + }, func(ctx context.Context, err error) error { + return fmt.Errorf("fallback_error") + }) + + Convey("the returned error should contain both errors and should be of type ErrTimeout", func() { + err := <-errChan + So(errors.Is(err, ErrTimeout), ShouldBeTrue) + So(err.Error(), ShouldEqual, "fallback failed with 'fallback_error'. run error was 'hystrix: timeout'") + }) + }) +} + func TestCloseCircuitAfterSuccess(t *testing.T) { Convey("when a circuit is open", t, func() { defer Flush()