Skip to content

Commit 983e27b

Browse files
authored
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 angular#15578 Closes angular#16492
1 parent c68b31c commit 983e27b

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

Diff for: src/ng/compile.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -1557,19 +1557,15 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
15571557
}
15581558
// We must run this hook in an apply since the $$postDigest runs outside apply
15591559
$rootScope.$apply(function() {
1560-
var errors = [];
15611560
for (var i = 0, ii = onChangesQueue.length; i < ii; ++i) {
15621561
try {
15631562
onChangesQueue[i]();
15641563
} catch (e) {
1565-
errors.push(e);
1564+
$exceptionHandler(e);
15661565
}
15671566
}
15681567
// Reset the queue to trigger a new schedule next time there is a change
15691568
onChangesQueue = undefined;
1570-
if (errors.length) {
1571-
throw errors;
1572-
}
15731569
});
15741570
} finally {
15751571
onChangesTtl++;

Diff for: test/ng/compileSpec.js

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

50775077
// The first component's error should be logged
5078-
var errors = $exceptionHandler.errors.pop();
5079-
expect(errors[0]).toEqual(new Error('bad hook'));
5078+
expect($exceptionHandler.errors.pop()).toEqual(new Error('bad hook'));
50805079

50815080
// The second component's changes should still be called
50825081
expect($log.info.logs.pop()).toEqual(['onChange']);
50835082
});
50845083
});
50855084

50865085

5087-
it('should collect up all `$onChanges` errors into one throw', function() {
5086+
it('should throw `$onChanges` errors immediately', function() {
50885087
function ThrowingController() {
50895088
this.$onChanges = function(change) {
50905089
throw new Error('bad hook: ' + this.prop);
@@ -5113,10 +5112,9 @@ describe('$compile', function() {
51135112

51145113
$rootScope.$apply('a = 42');
51155114

5116-
// Both component's error should be logged
5117-
var errors = $exceptionHandler.errors.pop();
5118-
expect(errors.pop()).toEqual(new Error('bad hook: 84'));
5119-
expect(errors.pop()).toEqual(new Error('bad hook: 42'));
5115+
// Both component's error should be logged individually
5116+
expect($exceptionHandler.errors.pop()).toEqual(new Error('bad hook: 84'));
5117+
expect($exceptionHandler.errors.pop()).toEqual(new Error('bad hook: 42'));
51205118
});
51215119
});
51225120
});

0 commit comments

Comments
 (0)