From 8c0bf8faac1540c8b02cd5e862ed8f13c536fb9a Mon Sep 17 00:00:00 2001 From: Daniel Scalzi Date: Sun, 20 Jan 2019 06:55:13 -0500 Subject: [PATCH] Improve error handling during launch (#21) If anything happens to the forked process, the main should now pick up on it and alert the user. Should no longer get 'stuck at 100%' issues when the forked process fails, for whatever reason. --- app/assets/js/distromanager.js | 7 +++- app/assets/js/scripts/landing.js | 69 ++++++++++++++++---------------- 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/app/assets/js/distromanager.js b/app/assets/js/distromanager.js index 4dc80a7..b6adefd 100644 --- a/app/assets/js/distromanager.js +++ b/app/assets/js/distromanager.js @@ -534,7 +534,12 @@ exports.pullRemote = function(){ const distroDest = path.join(ConfigManager.getLauncherDirectory(), 'distribution.json') request(opts, (error, resp, body) => { if(!error){ - data = DistroIndex.fromJSON(JSON.parse(body)) + + try { + data = DistroIndex.fromJSON(JSON.parse(body)) + } catch (e) { + reject(e) + } fs.writeFile(distroDest, body, 'utf-8', (err) => { if(!err){ diff --git a/app/assets/js/scripts/landing.js b/app/assets/js/scripts/landing.js index 31a6f92..d3588ed 100644 --- a/app/assets/js/scripts/landing.js +++ b/app/assets/js/scripts/landing.js @@ -254,6 +254,23 @@ refreshMojangStatuses() let mojangStatusListener = setInterval(() => refreshMojangStatuses(true), 300000) let serverStatusListener = setInterval(() => refreshServerStatus(true), 300000) +/** + * Shows an error overlay, toggles off the launch area. + * + * @param {string} title The overlay title. + * @param {string} desc The overlay description. + */ +function showLaunchFailure(title, desc){ + setOverlayContent( + title, + desc, + 'Okay' + ) + setOverlayHandler(null) + toggleOverlay(true) + toggleLaunchArea(false) +} + /* System (Java) Scan */ let sysAEx @@ -495,6 +512,16 @@ function dlAsync(login = true){ aEx.stdio[2].on('data', (data) => { loggerAEx.log(data) }) + aEx.on('error', (err) => { + loggerLaunchSuite.error('Error during launch', err) + showLaunchFailure('Error During Launch', err.message || 'See console (CTRL + Shift + i) for more details.') + }) + aEx.on('close', (code, signal) => { + if(code !== 0){ + loggerLaunchSuite.error(`AssetExec exited with code ${code}, assuming error.`) + showLaunchFailure('Error During Launch', 'See console (CTRL + Shift + i) for more details.') + } + }) // Establish communications between the AssetExec and current process. aEx.on('message', (m) => { @@ -575,24 +602,18 @@ function dlAsync(login = true){ loggerLaunchSuite.error('Error while downloading:', m.error) if(m.error.code === 'ENOENT'){ - setOverlayContent( + showLaunchFailure( 'Download Error', - 'Could not connect to the file server. Ensure that you are connected to the internet and try again.', - 'Okay' + 'Could not connect to the file server. Ensure that you are connected to the internet and try again.' ) - setOverlayHandler(null) } else { - setOverlayContent( + showLaunchFailure( 'Download Error', - 'Check the console for more details. Please try again.', - 'Okay' + 'Check the console (CTRL + Shift + i) for more details. Please try again.' ) - setOverlayHandler(null) } remote.getCurrentWindow().setProgressBar(-1) - toggleOverlay(true) - toggleLaunchArea(false) // Disconnect from AssetExec aEx.disconnect() @@ -644,14 +665,7 @@ function dlAsync(login = true){ data = data.trim() if(data.indexOf('Could not find or load main class net.minecraft.launchwrapper.Launch') > -1){ loggerLaunchSuite.error('Game launch failed, LaunchWrapper was not downloaded properly.') - setOverlayContent( - 'Error During Launch', - 'The main file, LaunchWrapper, failed to download properly. As a result, the game cannot launch.

To fix this issue, temporarily turn off your antivirus software and launch the game again.

If you have time, please submit an issue and let us know what antivirus software you use. We\'ll contact them and try to straighten things out.', - 'Okay' - ) - setOverlayHandler(null) - toggleOverlay(true) - toggleLaunchArea(false) + showLaunchFailure('Error During Launch', 'The main file, LaunchWrapper, failed to download properly. As a result, the game cannot launch.

To fix this issue, temporarily turn off your antivirus software and launch the game again.

If you have time, please submit an issue and let us know what antivirus software you use. We\'ll contact them and try to straighten things out.') } } @@ -681,14 +695,7 @@ function dlAsync(login = true){ } catch(err) { loggerLaunchSuite.error('Error during launch', err) - setOverlayContent( - 'Error During Launch', - 'Please check the console for more details.', - 'Okay' - ) - setOverlayHandler(null) - toggleOverlay(true) - toggleLaunchArea(false) + showLaunchFailure('Error During Launch', 'Please check the console (CTRL + Shift + i) for more details.') } } @@ -717,15 +724,7 @@ function dlAsync(login = true){ }, (err) => { loggerLaunchSuite.error('Unable to refresh distribution index.', err) if(DistroManager.getDistribution() == null){ - setOverlayContent( - 'Fatal Error', - 'Could not load a copy of the distribution index. See the console for more details.', - 'Okay' - ) - setOverlayHandler(null) - - toggleOverlay(true) - toggleLaunchArea(false) + showLaunchFailure('Fatal Error', 'Could not load a copy of the distribution index. See the console (CTRL + Shift + i) for more details.') // Disconnect from AssetExec aEx.disconnect()