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')) { 31 customizeModuleIsMissingMessage(error); 32 } 33} 34function errorHandler(originalHandler, error, isFatal) { 35 if (error instanceof Error) { 36 // Suppresses `"main" has not been registered` error only if it was caused by a different error. 37 // Otherwise, we want to show it, cause the user may forget to call `AppRegistry.registerComponent`. 38 if (wasHit && error.message?.includes('has not been registered. This can happen if')) { 39 return; 40 } 41 customizeError(error); 42 } 43 wasHit = true; 44 originalHandler(error, isFatal); 45} 46export function createErrorHandler(originalHandler) { 47 return (error, isFatal) => { 48 if (isErrorHandlingEnabled) { 49 errorHandler(originalHandler, error, isFatal); 50 return; 51 } 52 originalHandler(error, isFatal); 53 }; 54} 55export function disableErrorHandling() { 56 isErrorHandlingEnabled = false; 57} 58//# sourceMappingURL=DevLauncherErrorManager.js.map