From e639061fa8c7b06af53dcd123eb03304cc1d981a Mon Sep 17 00:00:00 2001 From: Daniel Scalzi Date: Sun, 19 Mar 2023 19:34:35 -0400 Subject: [PATCH] Hopefully catch all errors during launch process. --- app/assets/js/scripts/landing.js | 85 +++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 29 deletions(-) diff --git a/app/assets/js/scripts/landing.js b/app/assets/js/scripts/landing.js index c8709e1..3d1dfa8 100644 --- a/app/assets/js/scripts/landing.js +++ b/app/assets/js/scripts/landing.js @@ -103,24 +103,29 @@ function setLaunchEnabled(val){ // Bind launch button document.getElementById('launch_button').addEventListener('click', async e => { loggerLanding.info('Launching game..') - const server = (await DistroAPI.getDistribution()).getServerById(ConfigManager.getSelectedServer()) - const mcVersion = server.rawServer.minecraftVersion - const jExe = ConfigManager.getJavaExecutable(ConfigManager.getSelectedServer()) - if(jExe == null){ - await asyncSystemScan(server.effectiveJavaOptions) - } else { - - setLaunchDetails(Lang.queryJS('landing.launch.pleaseWait')) - toggleLaunchArea(true) - setLaunchPercentage(0, 100) - - const details = await validateSelectedJvm(ensureJavaDirIsRoot(jExe), server.effectiveJavaOptions.supported) - if(details != null){ - loggerLanding.info('Jvm Details', details) - await dlAsync() - } else { + try { + const server = (await DistroAPI.getDistribution()).getServerById(ConfigManager.getSelectedServer()) + const jExe = ConfigManager.getJavaExecutable(ConfigManager.getSelectedServer()) + if(jExe == null){ await asyncSystemScan(server.effectiveJavaOptions) + } else { + + setLaunchDetails(Lang.queryJS('landing.launch.pleaseWait')) + toggleLaunchArea(true) + setLaunchPercentage(0, 100) + + const details = await validateSelectedJvm(ensureJavaDirIsRoot(jExe), server.effectiveJavaOptions.supported) + if(details != null){ + loggerLanding.info('Jvm Details', details) + await dlAsync() + + } else { + await asyncSystemScan(server.effectiveJavaOptions) + } } + } catch(err) { + loggerLanding.error('Unhandled error in during launch process.', err) + showLaunchFailure('Error During Launch', 'See console (CTRL + Shift + i) for more details.') } }) @@ -319,9 +324,14 @@ async function asyncSystemScan(effectiveJavaOptions, launchAfter = true){ ) setOverlayHandler(() => { setLaunchDetails('Preparing Java Download..') - - downloadJava(effectiveJavaOptions, launchAfter) toggleOverlay(false) + + try { + downloadJava(effectiveJavaOptions, launchAfter) + } catch(err) { + loggerLanding.error('Unhandled error in Java Download', err) + showLaunchFailure('Error During Java Download', 'See console (CTRL + Shift + i) for more details.') + } }) setDismissHandler(() => { $('#overlayContent').fadeOut(250, () => { @@ -374,6 +384,10 @@ async function downloadJava(effectiveJavaOptions, launchAfter = true) { ConfigManager.getDataDirectory(), effectiveJavaOptions.distribution) + if(asset == null) { + throw new Error('Failed to find OpenJDK distribution.') + } + let received = 0 await downloadFile(asset.url, asset.path, ({ transferred }) => { received = transferred @@ -385,9 +399,8 @@ async function downloadJava(effectiveJavaOptions, launchAfter = true) { loggerLanding.warn(`Java Download: Expected ${asset.size} bytes but received ${received}`) if(!await validateLocalFile(asset.path, asset.algo, asset.hash)) { log.error(`Hashes do not match, ${asset.id} may be corrupted.`) - - // TODO Make error handling graceful. - throw new Error('JDK download had problems') + // Don't know how this could happen, but report it. + throw new Error('Downloaded JDK has bad hash, file may be corrupted.') } } @@ -492,18 +505,32 @@ async function dlAsync(login = true) { loggerLaunchSuite.info('Validating files.') setLaunchDetails('Validating file integrity..') - const invalidFileCount = await fullRepairModule.verifyFiles(percent => { - setLaunchPercentage(percent) - }) - setLaunchPercentage(100) + let invalidFileCount = 0 + try { + invalidFileCount = await fullRepairModule.verifyFiles(percent => { + setLaunchPercentage(percent) + }) + setLaunchPercentage(100) + } catch (err) { + loggerLaunchSuite.error('Error during file validation.') + showLaunchFailure('Error During File Verification', err.displayable || 'See console (CTRL + Shift + i) for more details.') + return + } + if(invalidFileCount > 0) { loggerLaunchSuite.info('Downloading files.') setLaunchDetails('Downloading files..') - await fullRepairModule.download(percent => { - setDownloadPercentage(percent) - }) - setDownloadPercentage(100) + try { + await fullRepairModule.download(percent => { + setDownloadPercentage(percent) + }) + setDownloadPercentage(100) + } catch(err) { + loggerLaunchSuite.error('Error during file download.') + showLaunchFailure('Error During File Download', err.displayable || 'See console (CTRL + Shift + i) for more details.') + return + } } else { loggerLaunchSuite.info('No invalid files, skipping download.') }