Skip to content

Commit

Permalink
Improve error handling during launch (#21)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dscalzi committed Jan 20, 2019
1 parent cb12c07 commit 8c0bf8f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 36 deletions.
7 changes: 6 additions & 1 deletion app/assets/js/distromanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
69 changes: 34 additions & 35 deletions app/assets/js/scripts/landing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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.<br><br>To fix this issue, temporarily turn off your antivirus software and launch the game again.<br><br>If you have time, please <a href="https://github.com/WesterosCraftCode/ElectronLauncher/issues">submit an issue</a> 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.<br><br>To fix this issue, temporarily turn off your antivirus software and launch the game again.<br><br>If you have time, please <a href="https://github.com/WesterosCraftCode/ElectronLauncher/issues">submit an issue</a> and let us know what antivirus software you use. We\'ll contact them and try to straighten things out.')
}
}

Expand Down Expand Up @@ -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.')

}
}
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 8c0bf8f

Please sign in to comment.