From a370e9d4cb7e7e203057624196e82c7b19701833 Mon Sep 17 00:00:00 2001 From: Jonas Hermsmeier Date: Wed, 28 Jun 2017 16:44:21 +0200 Subject: [PATCH] feat(gui): Show friendlier error dialog when opening images (#1557) * feat(gui): Friendly error dialog when opening image fails This displays a friendlier error dialog if opening an image fails due any reason (like i.e. an unsupported compression method) Change-Type: patch * test(image-stream): Add test for unsupported compression method * test(image-stream): Only check `error.description` when given * test(image-stream): Add zip-deflate64.zip --- .../pages/main/controllers/image-selection.js | 13 ++++++++++++- lib/shared/messages.js | 5 +++++ tests/image-stream/data/zip/zip-deflate64.zip | Bin 0 -> 21821 bytes tests/image-stream/tester.js | 4 ++-- tests/image-stream/zip.spec.js | 6 ++++++ 5 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 tests/image-stream/data/zip/zip-deflate64.zip diff --git a/lib/gui/pages/main/controllers/image-selection.js b/lib/gui/pages/main/controllers/image-selection.js index 8afdfa11..37882e2e 100644 --- a/lib/gui/pages/main/controllers/image-selection.js +++ b/lib/gui/pages/main/controllers/image-selection.js @@ -124,7 +124,18 @@ module.exports = function( this.selectImageByPath = (imagePath) => { imageStream.getImageMetadata(imagePath) .then(this.selectImage) - .catch(ErrorService.reportException); + .catch((error) => { + const imageError = errors.createUserError({ + title: 'Error opening image', + description: messages.error.openImage({ + imageBasename: path.basename(imagePath), + errorMessage: error.message + }) + }); + + OSDialogService.showError(imageError); + analytics.logException(error); + }); }; /** diff --git a/lib/shared/messages.js b/lib/shared/messages.js index 16b81c3e..1a91e778 100644 --- a/lib/shared/messages.js +++ b/lib/shared/messages.js @@ -87,6 +87,11 @@ module.exports = { invalidImage: _.template('<%= image.path %> is not a supported image type.'), + openImage: _.template([ + 'Something went wrong while opening <%= imageBasename %>\n\n', + 'Error: <%= errorMessage %>' + ].join('')), + elevationRequired: _.template('This should should be run with root/administrator permissions.'), flashFailure: _.template([ diff --git a/tests/image-stream/data/zip/zip-deflate64.zip b/tests/image-stream/data/zip/zip-deflate64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%p#G3|7oGpuMT|i;oz;T+Z(?8cgvRUWI4ET5(_KKUKSP`gT?fz4px>C_#4v3 Y_^ 0).to.be.true; } - m.chai.expect(error.description).to.be.a.string; - m.chai.expect(error.description.length > 0).to.be.true; }); }); }; diff --git a/tests/image-stream/zip.spec.js b/tests/image-stream/zip.spec.js index e9e58d42..7c24a43d 100644 --- a/tests/image-stream/zip.spec.js +++ b/tests/image-stream/zip.spec.js @@ -43,6 +43,12 @@ describe('ImageStream: ZIP', function() { 'Invalid archive image'); }); + describe('given a zip with an unsupported compression method', function() { + tester.expectError( + path.join(ZIP_PATH, 'zip-deflate64.zip'), + 'unsupported compression method: 9'); + }); + describe('given a zip directory containing multiple images', function() { tester.expectError( path.join(ZIP_PATH, 'zip-directory-multiple-images.zip'),