-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description Now on iOS is possible to catch JSError thrown from the worklet. ## Example ```js const a = () => { 'worklet'; throw new Error('exception_message') } const style = useAnimatedStyle(() => { 'worklet' if(_WORKLET) { try { a(); } catch(e) { console.log("SUCCESS!", e.message) } } return { width: withTiming(sv.value), }; }); ```
- Loading branch information
Showing
2 changed files
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
#include "RemoteObject.h" | ||
#include "FrozenObject.h" | ||
#include "RuntimeDecorator.h" | ||
#include <cxxabi.h> | ||
|
||
namespace reanimated { | ||
|
||
|
@@ -352,6 +353,9 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) { | |
} catch(jsi::JSError &e) { | ||
throw e; | ||
} catch(...) { | ||
if(demangleExceptionName(abi::__cxa_current_exception_type()->name()) == "facebook::jsi::JSError") { | ||
throw jsi::JSError(rt, "Javascript worklet error"); | ||
} | ||
// TODO find out a way to get the error's message on hermes | ||
jsi::Value location = jsThis->getProperty(rt, "__location"); | ||
std::string str = "Javascript worklet error"; | ||
|
@@ -407,6 +411,9 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) { | |
runtimeManager->errorHandler->setError(str); | ||
runtimeManager->errorHandler->raise(); | ||
} catch(...) { | ||
if(demangleExceptionName(abi::__cxa_current_exception_type()->name()) == "facebook::jsi::JSError") { | ||
throw jsi::JSError(rt, "Javascript worklet error"); | ||
} | ||
// TODO find out a way to get the error's message on hermes | ||
jsi::Value location = jsThis.getProperty(rt, "__location"); | ||
std::string str = "Javascript worklet error"; | ||
|
@@ -433,4 +440,15 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) { | |
throw "convert error"; | ||
} | ||
|
||
std::string ShareableValue::demangleExceptionName(std::string toDemangle) { | ||
int status = 0; | ||
char * buff = __cxxabiv1::__cxa_demangle(toDemangle.c_str(), nullptr, nullptr, &status); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
piaskowyk
Author
Member
|
||
if (!buff) { | ||
return toDemangle; | ||
} | ||
std::string demangled = buff; | ||
std::free(buff); | ||
return demangled; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wtf nice 😅