Skip to content

Commit

Permalink
upgrade: angular to v1.6.1; angular-ui-bootstrap to v2.5.0
Browse files Browse the repository at this point in the history
Angular 1.5 has a bug that causes angular's `$exceptionHandler`
to be called for rejected `$q` promises even if they have
a rejection handler. This bug caused duplicate error messages
in Etcher.

A consequence of upgrading to Angular 1.6 is that `$q` promises
without a rejection handler will throw `Possibly unhandled rejection`
errors. To avoid these errors, this commit moves code responsible
for opening a tooltip from the template to the controller and handles
the rejection.

Other packages upgraded:
- angular-moment to v1.0.1
- angular-ui-router to v0.4.2
- angular-mocks to v1.6.1

Change-type: patch
Changelog-Entry: Fix duplicate error messages
Fixes: #1082
See: angular/angular.js#7992
See: angular/angular.js#13662
  • Loading branch information
stefan-mihaila committed Feb 7, 2017
1 parent ea95177 commit d2e8a9f
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 31 deletions.
5 changes: 5 additions & 0 deletions lib/gui/modules/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

const angular = require('angular');
const _ = require('lodash');

const MODULE_NAME = 'Etcher.Modules.Error';
const error = angular.module(MODULE_NAME, [
Expand All @@ -41,6 +42,10 @@ error.service('ErrorService', function(AnalyticsService, OSDialogService) {
* ErrorService.reportException(new Error('Something happened'));
*/
this.reportException = (exception) => {
if (_.isUndefined(exception)) {
return;
}

OSDialogService.showError(exception, exception.description);
AnalyticsService.logException(exception);
};
Expand Down
19 changes: 18 additions & 1 deletion lib/gui/pages/main/controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = function(
FlashStateModel,
SettingsModel,
TooltipModalService,
ErrorService,
OSOpenExternalService
) {

Expand All @@ -31,7 +32,6 @@ module.exports = function(
this.state = FlashStateModel;
this.settings = SettingsModel;
this.external = OSOpenExternalService;
this.tooltipModal = TooltipModalService;

/**
* @summary Determine if the image step should be disabled
Expand Down Expand Up @@ -65,4 +65,21 @@ module.exports = function(
return !SelectionStateModel.hasImage() || this.shouldImageStepBeDisabled();
};

/**
* @summary Display a tooltip with the selected image details
* @function
* @public
*
* @returns {Promise}
*
* @example
* MainController.showSelectedImageDetails()
*/
this.showSelectedImageDetails = () => {
return TooltipModalService.show({
title: 'Image File Name',
message: SelectionStateModel.getImagePath()
}).catch(ErrorService.reportException);
};

};
5 changes: 4 additions & 1 deletion lib/gui/pages/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
const angular = require('angular');
const MODULE_NAME = 'Etcher.Pages.Main';

require('angular-moment');

const MainPage = angular.module(MODULE_NAME, [
'angularMoment',

require('angular-ui-router'),
require('angular-moment'),
require('angular-middle-ellipses'),
require('angular-seconds-to-date'),

Expand Down
5 changes: 1 addition & 4 deletions lib/gui/pages/main/templates/main.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@

<span class="glyphicon glyphicon-info-sign"
ng-class="{ 'text-disabled': main.shouldImageStepBeDisabled() }"
ng-click="main.tooltipModal.show({
title: 'Image File Name',
message: main.selection.getImagePath()
})"></span>
ng-click="main.showSelectedImageDetails()"></span>
</div>

<button class="button button-link step-footer"
Expand Down
30 changes: 15 additions & 15 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@
"removedrive": "^1.1.1"
},
"dependencies": {
"angular": "^1.5.3",
"angular": "^1.6.1",
"angular-if-state": "^1.0.0",
"angular-middle-ellipses": "^1.0.0",
"angular-moment": "^1.0.0-beta.6",
"angular-moment": "^1.0.1",
"angular-seconds-to-date": "^1.0.0",
"angular-ui-bootstrap": "^1.3.2",
"angular-ui-router": "^0.2.18",
"angular-ui-bootstrap": "^2.5.0",
"angular-ui-router": "^0.4.2",
"archive-type": "^3.2.0",
"bluebird": "^3.0.5",
"bootstrap-sass": "^3.3.5",
Expand Down Expand Up @@ -102,7 +102,7 @@
"yauzl": "^2.6.0"
},
"devDependencies": {
"angular-mocks": "^1.4.7",
"angular-mocks": "^1.6.1",
"browserify": "^13.0.1",
"cz-conventional-changelog": "^1.1.6",
"electron-builder": "^2.6.0",
Expand Down
10 changes: 5 additions & 5 deletions tests/gui/modules/image-writer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Browser: ImageWriter', function() {

describe('.flash()', function() {

describe('given a succesful write', function() {
describe('given a successful write', function() {

beforeEach(function() {
this.performWriteStub = m.sinon.stub(ImageWriterService, 'performWrite');
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('Browser: ImageWriter', function() {
});

ImageWriterService.flash('foo.img', '/dev/disk2');
ImageWriterService.flash('foo.img', '/dev/disk2');
ImageWriterService.flash('foo.img', '/dev/disk2').catch(angular.noop);
$rootScope.$apply();
m.chai.expect(this.performWriteStub).to.have.been.calledOnce;
});
Expand All @@ -83,7 +83,7 @@ describe('Browser: ImageWriter', function() {

});

describe('given an unsuccesful write', function() {
describe('given an unsuccessful write', function() {

beforeEach(function() {
this.performWriteStub = m.sinon.stub(ImageWriterService, 'performWrite');
Expand All @@ -97,13 +97,13 @@ describe('Browser: ImageWriter', function() {
});

it('should set flashing to false when done', function() {
ImageWriterService.flash('foo.img', '/dev/disk2');
ImageWriterService.flash('foo.img', '/dev/disk2').catch(angular.noop);
$rootScope.$apply();
m.chai.expect(FlashStateModel.isFlashing()).to.be.false;
});

it('should set the error code in the flash results', function() {
ImageWriterService.flash('foo.img', '/dev/disk2');
ImageWriterService.flash('foo.img', '/dev/disk2').catch(angular.noop);
$rootScope.$apply();
const flashResults = FlashStateModel.getFlashResults();
m.chai.expect(flashResults.errorCode).to.equal('FOO');
Expand Down

0 comments on commit d2e8a9f

Please sign in to comment.