fix: stop assuming that error.stack is defined #296
Merged
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.
Checklist
Why
Hi there, I am experiencing an issue in our app where instead of an expected exception being logged in the redbox in development, the following error is logged instead:
How
The stack trace in the redbox lead me to the function in question. By adding a
console.error
log in the filenode_modules/sentry-expo/build/integrations/bare.js
I verified that an exception was thrown by my app which has an undefinederror.stack
property.This happened to be an
AssertionError
, thrown byassert.equal
from assert. I'm sure it's possible to reproduce this in another project using this code:As this is a straight port from Node.js's assert module, I'm sure the error exported from this is not 100% compatible with the 'native'
Error
. We ideally don't want to removeassert
(which is used in a lot of places, including shared Node.js/React Native code), so (in my opinion) the best solution is just to fix this problem here.From a type perspective,
error
isany
, so we shouldn't assume thaterror.stack
exists or is a string. (I canthrow { whatever: true }
.)Test Plan
I am sorry but I don't have the time to create a minimal reproducible example. I tested this change by manually applying this patch using
patch-package
: https://gist.github.com/lachenmayer/e06438d58a5948bf8149bb4268e4c0ddBefore
This error is logged in the console & shown in the redbox:
After - expected behavior
Error logged after - the exact value is irrelevant, it's the error that was actually thrown by our app: