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

Bug Description

image

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 clean and 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

  1. 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)

Most upvoted comments

@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. require has different semantics that fopen. Maybe that’s where the confusion is coming from?

@rpopovici I was able to reproduce the problem with the hdb tool and this simple source:

function foo(a) {
    try {
        throw a+10;
    } catch (err) {
        print(err);
        var xxx = err;
        debugger;
    }
}

foo(5);

And the following debugging session:

hdb catch.js
15
Break on 'debugger' statement in foo: catch.js[2]:7:9
(hdb) exec a
5
(hdb) exec xxx
15
(hdb) exec err
Exception: ReferenceError: Property 'err' doesn't exist
  0: eval: JavaScript:1:1
  1: foo: catch.js:7:9
  2: global: catch.js:11:4
Thrown value is: { message: Property 'err' doesn't exist }
(hdb) info variables
this = undefined
 0:          a = 5
 0:        xxx = 15
 0: ?anon_0_err = 15

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 err to another variable works. I can see the error object in flipper:

jsEngine: "hermes"
message: "Network request failed"
stack: "TypeError: Network request failed...