hermes: Crash on try catch saying that the error in the catch does not exist
Bug Description

try {
const result = await resolvePromise(promise);
isCurrentlyMounted &&
debounceSetState((prev) => ({
...prev,
fetching: false,
loading: false,
result,
}));
} catch (error) {
// const catchError = error;
isCurrentlyMounted &&
debounceSetState((prev) => ({
...prev,
fetching: false,
loading: false,
error: error as Error,
}));
}
When trying to run the above code, I get the error saying that ‘error’ does not exist, if I create the variable ‘catchError’ and assign the error to it, then it goes through without a problem.
I started seeing this issue after I migrated to react native 0.70.6 and started using hermes. This is happening on a iOS simulator.
- I have run
gradle cleanand confirmed this bug does not occur with JSC
Hermes version: 0.70.6 React Native version (if any): 0.70.6 OS version (if any): iOS 16.0 Platform (most likely one of arm64-v8a, armeabi-v7a, x86, x86_64): x86_64
Steps To Reproduce
- Try to use the catch error inside a function with a different scope
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 1
- Comments: 19 (8 by maintainers)
@woowalker the example you shared is unrelated to the GH issue. I don’t think the
require(defined on RN itself) is expected to throw. The “red box error” you’re seeing is triggered by the require function call itself. In other words, the call finished gracefully after pushing a view to display the error.requirehas different semantics thatfopen. Maybe that’s where the confusion is coming from?@rpopovici I was able to reproduce the problem with the
hdbtool and this simple source:And the following debugging session:
Clearly, the debugger doesn’t know about the variable
err.It doesn’t seem like this is the same problem as the one reported by @rogeriomoura, but this is a legitimate bug. I am opening a new issue for tracking it.
@tmikov Assigning
errto another variable works. I can see the error object in flipper: