Use of instanceof
Causes Unexpected Behavior in defaultRetryDecider
- Jest
#4273
Closed
3 tasks done
Labels
bug
This issue is a bug.
closed-for-staleness
p2
This is a standard priority issue
response-requested
Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.
Checkboxes for prior research
Describe the bug
Jest has problems (+, +) with
instanceof
and therefore the following implementation forasSdkError
will always fall back to the last line (AWS SDK error wrapper for ...
) which causes all of theerror.XXX
properties to be removed (likeerror.name
which will be subsequently needed).aws-sdk-js-v3/packages/middleware-retry/src/util.ts
Lines 3 to 8 in fcfb59f
The
shouldRetry
function uses thedefaultRetryDecider
:aws-sdk-js-v3/packages/middleware-retry/src/StandardRetryStrategy.ts
Line 101 in fcfb59f
aws-sdk-js-v3/packages/middleware-retry/src/StandardRetryStrategy.ts
Line 47 in fcfb59f
Because the
defaultRetryDecider
is calling functions that rely onerror.name
which is replaced by the earliernew Error
therefore they don't work as expected:aws-sdk-js-v3/packages/middleware-retry/src/retryDecider.ts
Lines 9 to 15 in fcfb59f
For example
isTransientError
is usingerror.name
as follows:aws-sdk-js-v3/packages/service-error-classification/src/index.ts
Lines 26 to 29 in e7b1535
SDK version number
latest
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
v18.11.0
Reproduction Steps
Use the following code and place a breakpoint on
asSdkError
first line to see the error is being wrapped (not because it's not a true error, but becauseinstanceof
call fails). The test is just created to cause an error to be thrown.Observed Behavior
Due to the failure of
instanceof
to act as it should, it's falling back tonew Error
line and therefore causingdefaultRetryDecider
to have unexpected behavior.Expected Behavior
The
instanceof
should be replaced by something that works throughout different environments, and thedefaultRetryDecider
should be working.Possible Solution
Use of
(error as {name?: ...}).name?
maybe fixes the issue and theinstanceof
is no longer needed.Additional Information/Context
No response
The text was updated successfully, but these errors were encountered: