Fix error on call.toString() where stack has fewer than 4 lines. #1359
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1066
Purpose
Fixes #1066 by not calling
String#replace
onundefined
, which could happen when an error stack had fewer than 4 lines (e.g. when the offending function was called point-free inPromise#then()
).Background
Here's a very simple reduced test case that reproduces the issue:
Because
stub2
is invoked directly by the VM, it has nothing in its stack. That breakscall.toString()
, which assumes each stack consists of at least 4 lines (the first 3 of which are Sinon-related, and the 4th being the beginning of the user's call stack).Solution
Simply safe-guard against the
String#replace()
call by providing a defaultstack
value of"unknown"
.How to verify
npm install
npm test
The new test
sinonSpy.call > call.toString > does not throw when the call stack is empty
will pass.Or try the example under
Background
above.