From 535991b4b4eae7831575fb4b2a8d796adbfbb3c3 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Wed, 11 Jul 2018 16:36:34 -0700 Subject: [PATCH] Improve defence against corrupt skins --- experiments/automatedScreenshots/shooter.js | 10 +++++--- js/actionCreators/files.js | 26 +++++++++++++-------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/experiments/automatedScreenshots/shooter.js b/experiments/automatedScreenshots/shooter.js index a6baa1de..4c71146e 100644 --- a/experiments/automatedScreenshots/shooter.js +++ b/experiments/automatedScreenshots/shooter.js @@ -35,9 +35,13 @@ class Shooter { _validateZip(u) { return new Promise((resolve, reject) => { - fs.readFile(u, (err, buffer) => { - JSZip.loadAsync(buffer).then(resolve, reject); - }); + try { + fs.readFile(u, (err, buffer) => { + JSZip.loadAsync(buffer).then(resolve, reject); + }); + } catch (e) { + reject(e); + } }); } diff --git a/js/actionCreators/files.js b/js/actionCreators/files.js index 25299a37..e0aaf14e 100644 --- a/js/actionCreators/files.js +++ b/js/actionCreators/files.js @@ -82,16 +82,22 @@ export function loadFilesFromReferences( export function setSkinFromArrayBuffer(arrayBuffer) { return async dispatch => { dispatch({ type: LOADING }); - const skinData = await skinParser(arrayBuffer); - dispatch({ - type: SET_SKIN_DATA, - skinImages: skinData.images, - skinColors: skinData.colors, - skinPlaylistStyle: skinData.playlistStyle, - skinCursors: skinData.cursors, - skinRegion: skinData.region, - skinGenLetterWidths: skinData.genLetterWidths - }); + try { + const skinData = await skinParser(arrayBuffer); + dispatch({ + type: SET_SKIN_DATA, + skinImages: skinData.images, + skinColors: skinData.colors, + skinPlaylistStyle: skinData.playlistStyle, + skinCursors: skinData.cursors, + skinRegion: skinData.region, + skinGenLetterWidths: skinData.genLetterWidths + }); + } catch (e) { + console.error(e); + dispatch({ type: LOADED }); + alert(`Failed to parse skin`); + } }; }