UNPKG

react-native-filament

Version:

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

49 lines (46 loc) 1.53 kB
import { Worklets } from 'react-native-worklets-core'; /** * Report an error to react native's `ErrorUtils` if available, or log to console otherwise. */ export 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 = 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); }); export 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); }; export const wrapWithErrorHandler = callback => { return (...args) => { 'worklet'; try { return callback(...args); } catch (error) { reportWorkletError(error); throw error; } }; }; //# sourceMappingURL=ErrorUtils.js.map