Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit b7d1e0f

Browse files
committed
fix($compile): throw error in $onChanges immediately
This brings it in line with how we throw errors in a digest cycle, and also avoids throwing an array. Closes #15578 Closes #16492
1 parent 31ea071 commit b7d1e0f

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

src/ng/compile.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -1619,19 +1619,15 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
16191619
}
16201620
// We must run this hook in an apply since the $$postDigest runs outside apply
16211621
$rootScope.$apply(function() {
1622-
var errors = [];
16231622
for (var i = 0, ii = onChangesQueue.length; i < ii; ++i) {
16241623
try {
16251624
onChangesQueue[i]();
16261625
} catch (e) {
1627-
errors.push(e);
1626+
$exceptionHandler(e);
16281627
}
16291628
}
16301629
// Reset the queue to trigger a new schedule next time there is a change
16311630
onChangesQueue = undefined;
1632-
if (errors.length) {
1633-
throw errors;
1634-
}
16351631
});
16361632
} finally {
16371633
onChangesTtl++;

test/ng/compileSpec.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -4956,16 +4956,15 @@ describe('$compile', function() {
49564956
$rootScope.$apply('a = 42');
49574957

49584958
// The first component's error should be logged
4959-
var errors = $exceptionHandler.errors.pop();
4960-
expect(errors[0]).toEqual(new Error('bad hook'));
4959+
expect($exceptionHandler.errors.pop()).toEqual(new Error('bad hook'));
49614960

49624961
// The second component's changes should still be called
49634962
expect($log.info.logs.pop()).toEqual(['onChange']);
49644963
});
49654964
});
49664965

49674966

4968-
it('should collect up all `$onChanges` errors into one throw', function() {
4967+
it('should throw `$onChanges` errors immediately', function() {
49694968
function ThrowingController() {
49704969
this.$onChanges = function(change) {
49714970
throw new Error('bad hook: ' + this.prop);
@@ -4994,10 +4993,9 @@ describe('$compile', function() {
49944993

49954994
$rootScope.$apply('a = 42');
49964995

4997-
// Both component's error should be logged
4998-
var errors = $exceptionHandler.errors.pop();
4999-
expect(errors.pop()).toEqual(new Error('bad hook: 84'));
5000-
expect(errors.pop()).toEqual(new Error('bad hook: 42'));
4996+
// Both component's error should be logged individually
4997+
expect($exceptionHandler.errors.pop()).toEqual(new Error('bad hook: 84'));
4998+
expect($exceptionHandler.errors.pop()).toEqual(new Error('bad hook: 42'));
50014999
});
50025000
});
50035001
});

0 commit comments

Comments
 (0)