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
This commit is contained in:
Jonas Hermsmeier 2017-06-28 16:44:21 +02:00 committed by GitHub
parent 65210e4cbc
commit a370e9d4cb
5 changed files with 25 additions and 3 deletions

View File

@ -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);
});
};
/**

View File

@ -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([

Binary file not shown.

View File

@ -50,9 +50,9 @@ exports.expectError = function(file, errorMessage, errorDetail) {
m.chai.expect(error.message).to.equal(errorMessage);
if (errorDetail) {
m.chai.expect(error.description).to.contain(errorDetail);
m.chai.expect(error.description).to.be.a.string;
m.chai.expect(error.description.length > 0).to.be.true;
}
m.chai.expect(error.description).to.be.a.string;
m.chai.expect(error.description.length > 0).to.be.true;
});
});
};

View File

@ -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'),