Also report non-fatal non-warning errors (#48104)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48104

Just porting over the logic after D28815228.

Changelog: [Internal]

Reviewed By: mlord93

Differential Revision: D66563226

fbshipit-source-id: 41e21812dd0b2104fa66b970212f51bbb77d910b
This commit is contained in:
Ramanpreet Nara
2024-12-05 09:42:44 -08:00
committed by Facebook GitHub Bot
parent 00d5caee99
commit 2f0977d8e4
@@ -29,9 +29,12 @@ bool isLooselyNull(const jsi::Value& value) {
return value.isNull() || value.isUndefined();
}
bool isEmptyString(jsi::Runtime& runtime, const jsi::Value& value) {
bool isEqualTo(
jsi::Runtime& runtime,
const jsi::Value& value,
const std::string& str) {
return jsi::Value::strictEquals(
runtime, value, jsi::String::createFromUtf8(runtime, ""));
runtime, value, jsi::String::createFromUtf8(runtime, str));
}
std::string stringifyToCpp(jsi::Runtime& runtime, const jsi::Value& value) {
@@ -265,7 +268,7 @@ void JsErrorHandler::handleErrorWithCppPipeline(
}
auto nameValue = errorObj.getProperty(runtime, "name");
auto name = (isLooselyNull(nameValue) || isEmptyString(runtime, nameValue))
auto name = (isLooselyNull(nameValue) || isEqualTo(runtime, nameValue, ""))
? std::nullopt
: std::optional(stringifyToCpp(runtime, nameValue));
@@ -383,14 +386,19 @@ void JsErrorHandler::handleErrorWithCppPipeline(
return;
}
if (isFatal) {
if (_hasHandledFatalError) {
return;
}
_hasHandledFatalError = true;
}
auto errorType = errorObj.getProperty(runtime, "type");
auto isWarn = isEqualTo(runtime, errorType, "warn");
_onJsError(runtime, parsedError);
if (isFatal || !isWarn) {
if (isFatal) {
if (_hasHandledFatalError) {
return;
}
_hasHandledFatalError = true;
}
_onJsError(runtime, parsedError);
}
}
void JsErrorHandler::registerErrorListener(