UNPKG

@embrace-io/react-native

Version:
57 lines (56 loc) 2.38 kB
"use strict"; /** * Component Error API * * Provides automatic logging of React component rendering errors that include * a component stack trace. This is used internally by the SDK's global error * handler to capture additional context about where in the React tree an error occurred. * * @see {@link https://embrace.io/docs/react-native/features/render-errors | Render Errors Documentation} */ Object.defineProperty(exports, "__esModule", { value: true }); exports.logIfComponentError = void 0; const promiseHandler_1 = require("../utils/promiseHandler"); const EmbraceManagerModule_1 = require("../EmbraceManagerModule"); /** * Type guard that checks whether an error is a React component rendering error * by looking for the presence of a `componentStack` property. */ const isJSXError = (error) => { return "componentStack" in error; }; /** * Logs errors with additional React component stack information if available. * * This function checks if the provided error is a React Native rendering error * (i.e., it includes a `componentStack` property). If the `componentStack` is * present and non-empty the error details are logged using * `EmbraceManagerModule.logMessageWithSeverityAndProperties`, including the message * and the component stack trace. * * NOTES * - The `componentStack` provides a trace of the React component tree at the time * of the error but does not include line or column numbers. * - This function is complementary to other logging mechanisms that capture more * detailed stack traces, including line and column numbers. * * Example `componentStack` trace: * ``` * in App * in RCTView * in Unknown * in AppContainer * ``` * * @param error - The error object to be checked and logged. * @returns A promise that resolves to `true` if the error was logged, or `false` * if the error was not a React Native rendering error or the `componentStack` was empty. */ const logIfComponentError = (error) => { if (!isJSXError(error) || error.componentStack === "") { return Promise.resolve(false); } const { message, componentStack } = error; return (0, promiseHandler_1.safePromise)(EmbraceManagerModule_1.EmbraceManagerModule.logMessageWithSeverityAndProperties(message, "error", {}, componentStack, true), "logIfComponentError", false); }; exports.logIfComponentError = logIfComponentError;