1let isErrorHandlingEnabled = true; 2let wasHit = false; // whether the original error handler was called 3const unavailableErrorPossibleSolutions = `Some possible solutions: 4- Make sure that the method is available on the current platform. 5- Make sure you're using the newest available version of this development client. 6- Make sure you're running a compatible version of your JavaScript code. 7- If you've installed a new library recently, you may need to make a new development client build.`; 8const moduleIsMissingPossibleSolutions = `Some possible solutions: 9- Make sure you're using the newest available version of this development client. 10- Make sure you're running a compatible version of your JavaScript code. 11- If you've installed a new library recently, you may need to make a new development client build.`; 12function customizeUnavailableMessage(error) { 13 error.message += '\n\n' + unavailableErrorPossibleSolutions; 14} 15function customizeModuleIsMissingMessage(error) { 16 error.message = `Your JavaScript code tried to access a native module that doesn't exist in this development client. 17 18${moduleIsMissingPossibleSolutions}`; 19} 20function customizeError(error) { 21 if ('code' in error) { 22 // It's a CodedError from expo modules 23 switch (error.code) { 24 case 'ERR_UNAVAILABLE': { 25 customizeUnavailableMessage(error); 26 break; 27 } 28 } 29 } 30 else if (error.message.includes('Native module cannot be null') || // RN 0.64 and below message 31 error.message.includes('`new NativeEventEmitter()` requires a non-null argument.') // RN 0.65+ message 32 ) { 33 customizeModuleIsMissingMessage(error); 34 } 35} 36function errorHandler(originalHandler, error, isFatal) { 37 if (error instanceof Error) { 38 // Suppresses `"main" has not been registered` error only if it was caused by a different error. 39 // Otherwise, we want to show it, cause the user may forget to call `AppRegistry.registerComponent`. 40 if (wasHit && error.message?.includes('has not been registered. This can happen if')) { 41 return; 42 } 43 customizeError(error); 44 } 45 wasHit = true; 46 originalHandler(error, isFatal); 47} 48export function createErrorHandler(originalHandler) { 49 return (error, isFatal) => { 50 if (isErrorHandlingEnabled) { 51 errorHandler(originalHandler, error, isFatal); 52 return; 53 } 54 originalHandler(error, isFatal); 55 }; 56} 57export function disableErrorHandling() { 58 isErrorHandlingEnabled = false; 59} 60//# sourceMappingURL=DevLauncherErrorManager.js.map