UNPKG

react-native-filament

Version:

A real-time physically based 3D rendering engine for React Native

57 lines (54 loc) 1.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.reportError = reportError; exports.wrapWithErrorHandler = exports.reportWorkletError = void 0; var _reactNativeWorkletsCore = require("react-native-worklets-core"); /** * Report an error to react native's `ErrorUtils` if available, or log to console otherwise. */ function reportError(error, fatal) { // @ts-expect-error this is defined by react-native. if (global.ErrorUtils != null) { if (fatal) { // @ts-expect-error this is defined by react-native. global.ErrorUtils.reportFatalError(error); } else { // @ts-expect-error this is defined by react-native. global.ErrorUtils.reportError(error); } } else { console.error(`An unknown Filament error occurred!`, error); } } const throwErrorOnJS = _reactNativeWorkletsCore.Worklets.createRunOnJS((message, stack, fatal) => { const error = new Error(); error.message = message; error.stack = stack; error.name = 'Filament Error'; // @ts-expect-error this is react-native specific error.jsEngine = 'Filament'; // From react-native: reportError(error, fatal); }); const reportWorkletError = (error, fatal = true) => { 'worklet'; const safeError = error; const message = safeError != null && 'message' in safeError ? safeError.message : 'Filament threw an error.'; throwErrorOnJS(message, safeError === null || safeError === void 0 ? void 0 : safeError.stack, fatal); }; exports.reportWorkletError = reportWorkletError; const wrapWithErrorHandler = callback => { return (...args) => { 'worklet'; try { return callback(...args); } catch (error) { reportWorkletError(error); throw error; } }; }; exports.wrapWithErrorHandler = wrapWithErrorHandler; //# sourceMappingURL=ErrorUtils.js.map