Hopefully catch all errors during launch process.

This commit is contained in:
Daniel Scalzi 2023-03-19 19:34:35 -04:00
parent e3af7669d8
commit e639061fa8
No known key found for this signature in database
GPG Key ID: 9E3E2AFE45328AA5

View File

@ -103,8 +103,8 @@ function setLaunchEnabled(val){
// Bind launch button
document.getElementById('launch_button').addEventListener('click', async e => {
loggerLanding.info('Launching game..')
try {
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)
@ -118,10 +118,15 @@ document.getElementById('launch_button').addEventListener('click', async e => {
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.')
}
})
// Bind settings button
@ -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 => {
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..')
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.')
}