-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($q): treat thrown errors as regular rejections #15213
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3052,8 +3052,8 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | |
|
||
$compileNode.empty(); | ||
|
||
$templateRequest(templateUrl) | ||
.then(function(content) { | ||
$templateRequest(templateUrl). | ||
then(function(content) { | ||
var compileNode, tempTemplateAttrs, $template, childBoundTranscludeFn; | ||
|
||
content = denormalizeTemplate(content); | ||
|
@@ -3131,7 +3131,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | |
childBoundTranscludeFn); | ||
} | ||
linkQueue = null; | ||
}).catch(noop); | ||
}). | ||
catch(function(error) { | ||
if (error instanceof Error) { | ||
$exceptionHandler(error); | ||
} | ||
}). | ||
catch(noop); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This catch shouldn't be needed. The one above it is already catching all errors and is not re-throwing or returning a rejected promise, so this should be unreachable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Depends on what the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ok, never dawned on me that would be a valid thing to do. |
||
|
||
return function delayedNodeLinkFn(ignoreChildLinkFn, scope, node, rootElement, boundTranscludeFn) { | ||
var childBoundTranscludeFn = boundTranscludeFn; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1854,17 +1854,18 @@ describe('$compile', function() { | |
)); | ||
|
||
|
||
it('should throw an error and clear element content if the template fails to load', inject( | ||
function($compile, $httpBackend, $rootScope) { | ||
$httpBackend.expect('GET', 'hello.html').respond(404, 'Not Found!'); | ||
element = $compile('<div><b class="hello">content</b></div>')($rootScope); | ||
it('should throw an error and clear element content if the template fails to load', | ||
inject(function($compile, $exceptionHandler, $httpBackend, $rootScope) { | ||
$httpBackend.expect('GET', 'hello.html').respond(404, 'Not Found!'); | ||
element = $compile('<div><b class="hello">content</b></div>')($rootScope); | ||
|
||
expect(function() { | ||
$httpBackend.flush(); | ||
}).toThrowMinErr('$compile', 'tpload', 'Failed to load template: hello.html'); | ||
expect(sortedHtml(element)).toBe('<div><b class="hello"></b></div>'); | ||
} | ||
)); | ||
$httpBackend.flush(); | ||
|
||
expect(sortedHtml(element)).toBe('<div><b class="hello"></b></div>'); | ||
expect($exceptionHandler.errors[0].message).toMatch( | ||
/^\[\$compile:tpload] Failed to load template: hello\.html/); | ||
}) | ||
); | ||
|
||
|
||
it('should prevent multiple templates per element', function() { | ||
|
@@ -1878,13 +1879,15 @@ describe('$compile', function() { | |
templateUrl: 'template.html' | ||
})); | ||
}); | ||
inject(function($compile, $httpBackend) { | ||
inject(function($compile, $exceptionHandler, $httpBackend) { | ||
$httpBackend.whenGET('template.html').respond('<p>template.html</p>'); | ||
expect(function() { | ||
$compile('<div><div class="sync async"></div></div>'); | ||
$httpBackend.flush(); | ||
}).toThrowMinErr('$compile', 'multidir', 'Multiple directives [async, sync] asking for template on: ' + | ||
'<div class="sync async">'); | ||
|
||
$compile('<div><div class="sync async"></div></div>'); | ||
$httpBackend.flush(); | ||
|
||
expect($exceptionHandler.errors[0].message).toMatch(new RegExp( | ||
'^\\[\\$compile:multidir] Multiple directives \\[async, sync] asking for ' + | ||
'template on: <div class="sync async">')); | ||
}); | ||
}); | ||
|
||
|
@@ -2667,14 +2670,15 @@ describe('$compile', function() { | |
); | ||
|
||
it('should not allow more than one isolate/new scope creation per element regardless of `templateUrl`', | ||
inject(function($httpBackend) { | ||
inject(function($exceptionHandler, $httpBackend) { | ||
$httpBackend.expect('GET', 'tiscope.html').respond('<div>Hello, world !</div>'); | ||
|
||
expect(function() { | ||
compile('<div class="tiscope-a; scope-b"></div>'); | ||
$httpBackend.flush(); | ||
}).toThrowMinErr('$compile', 'multidir', 'Multiple directives [scopeB, tiscopeA] ' + | ||
'asking for new/isolated scope on: <div class="tiscope-a; scope-b ng-scope">'); | ||
compile('<div class="tiscope-a; scope-b"></div>'); | ||
$httpBackend.flush(); | ||
|
||
expect($exceptionHandler.errors[0].message).toMatch(new RegExp( | ||
'^\\[\\$compile:multidir] Multiple directives \\[scopeB, tiscopeA] ' + | ||
'asking for new/isolated scope on: <div class="tiscope-a; scope-b ng-scope">')); | ||
}) | ||
); | ||
|
||
|
@@ -8875,28 +8879,29 @@ describe('$compile', function() { | |
'<div class="foo" ng-transclude></div>' + | ||
'</div>', | ||
transclude: true | ||
|
||
})); | ||
|
||
$compileProvider.directive('noTransBar', valueFn({ | ||
templateUrl: 'noTransBar.html', | ||
transclude: false | ||
|
||
})); | ||
}); | ||
|
||
inject(function($compile, $rootScope, $templateCache) { | ||
inject(function($compile, $exceptionHandler, $rootScope, $templateCache) { | ||
$templateCache.put('noTransBar.html', | ||
'<div>' + | ||
// This ng-transclude is invalid. It should throw an error. | ||
'<div class="bar" ng-transclude></div>' + | ||
'</div>'); | ||
|
||
expect(function() { | ||
element = $compile('<div trans-foo>content</div>')($rootScope); | ||
$rootScope.$apply(); | ||
}).toThrowMinErr('ngTransclude', 'orphan', | ||
'Illegal use of ngTransclude directive in the template! No parent directive that requires a transclusion found. Element: <div class="bar" ng-transclude="">'); | ||
element = $compile('<div trans-foo>content</div>')($rootScope); | ||
$rootScope.$digest(); | ||
|
||
expect($exceptionHandler.errors[0][1]).toBe('<div class="bar" ng-transclude="">'); | ||
expect($exceptionHandler.errors[0][0].message).toMatch(new RegExp( | ||
'^\\[ngTransclude:orphan] Illegal use of ngTransclude directive in the ' + | ||
'template! No parent directive that requires a transclusion found. Element: ' + | ||
'<div class="bar" ng-transclude="">')); | ||
}); | ||
}); | ||
|
||
|
@@ -9706,12 +9711,15 @@ describe('$compile', function() { | |
transclude: 'element' | ||
})); | ||
}); | ||
inject(function($compile, $httpBackend) { | ||
inject(function($compile, $exceptionHandler, $httpBackend) { | ||
$httpBackend.expectGET('template.html').respond('<p second>template.html</p>'); | ||
|
||
$compile('<div template first></div>'); | ||
expect(function() { | ||
$httpBackend.flush(); | ||
}).toThrowMinErr('$compile', 'multidir', /Multiple directives \[first, second\] asking for transclusion on: <p .+/); | ||
$httpBackend.flush(); | ||
|
||
expect($exceptionHandler.errors[0].message).toMatch(new RegExp( | ||
'^\\[\\$compile:multidir] Multiple directives \\[first, second] asking for ' + | ||
'transclusion on: <p ')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should have a helper function for checking the exception handler message? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be helpful indeed. I'll add one. |
||
}); | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you're a "dots at the end of the line" kind of guy eh?
This is not in-keeping with the rest of the codebase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Knee-jerk reaction, sorry 😞 I'll amend.
(Although, there are some occurrences and I myself have sneaked in a couple of those lately 😛)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a search of the
src
folder for/\w+\.$/
and didn't find any - although there were lots of matches for sentences in the docs and I might have missed the code ones.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was a little more lucky with my search (without even taking the
test/
directory into account, because of too many occurrences) 😃 :https://github.com/angular/angular.js/blob/823295f/compare-master-to-stable.js#L75-L81
https://github.com/angular/angular.js/blob/823295f/compare-master-to-stable.js#L93-L104
https://github.com/angular/angular.js/blob/823295f/compare-master-to-stable.js#L110-L124
https://github.com/angular/angular.js/blob/823295f/compare-master-to-stable.js#L132-L142
https://github.com/angular/angular.js/blob/823295f/compare-master-to-stable.js#L154-L155
https://github.com/angular/angular.js/blob/823295f/compare-master-to-stable.js#L160-L164
https://github.com/angular/angular.js/blob/823295f/docs/app/test/errorSpec.js#L6-L7
https://github.com/angular/angular.js/blob/823295f/i18n/e2e/i18n-e2e.js#L73-L82
https://github.com/angular/angular.js/blob/823295f/i18n/e2e/i18n-e2e.js#L171-L172
https://github.com/angular/angular.js/blob/823295f/i18n/src/closureI18nExtractor.js#L93-L100
https://github.com/angular/angular.js/blob/823295f/lib/grunt/utils.js#L206-L207
https://github.com/angular/angular.js/blob/823295f/src/Angular.js#L1406-L1409
https://github.com/angular/angular.js/blob/823295f/src/Angular.js#L1425-L1433
https://github.com/angular/angular.js/blob/823295f/src/AngularPublic.js#L173-L174
https://github.com/angular/angular.js/blob/823295f/src/AngularPublic.js#L218-L223
https://github.com/angular/angular.js/blob/823295f/src/jqLite.js#L153-L154
https://github.com/angular/angular.js/blob/823295f/src/jqLite.js#L412-L413
https://github.com/angular/angular.js/blob/823295f/src/ng/cacheFactory.js#L66-L67
https://github.com/angular/angular.js/blob/823295f/src/ng/compile.js#L3292-L3293
https://github.com/angular/angular.js/blob/823295f/src/ng/exceptionHandler.js#L25-L26
https://github.com/angular/angular.js/blob/823295f/src/ng/http.js#L893-L894
https://github.com/angular/angular.js/blob/823295f/src/ng/interpolate.js#L111-L112
https://github.com/angular/angular.js/blob/823295f/src/ng/sce.js#L42-L44
https://github.com/angular/angular.js/blob/823295f/src/ng/directive/ngClass.js#L300-L301
https://github.com/angular/angular.js/blob/823295f/src/ng/directive/ngClass.js#L359-L362
https://github.com/angular/angular.js/blob/823295f/src/ng/directive/ngClass.js#L407-L410
https://github.com/angular/angular.js/blob/823295f/src/ng/directive/ngCloak.js#L46-L49
https://github.com/angular/angular.js/blob/823295f/src/ng/directive/ngModel.js#L94-L95
https://github.com/angular/angular.js/blob/823295f/src/ng/directive/ngModel.js#L160-L161
https://github.com/angular/angular.js/blob/823295f/src/ng/filter/filters.js#L74-L75
https://github.com/angular/angular.js/blob/823295f/src/ng/filter/filters.js#L563-L570
https://github.com/angular/angular.js/blob/823295f/src/ngAria/aria.js#L56-L57
https://github.com/angular/angular.js/blob/823295f/src/ngCookies/cookies.js#L19-L20
https://github.com/angular/angular.js/blob/823295f/src/ngCookies/cookieStore.js#L3-L4
https://github.com/angular/angular.js/blob/823295f/src/ngResource/resource.js#L431-L432
https://github.com/angular/angular.js/blob/823295f/src/ngResource/resource.js#L477-L478
https://github.com/angular/angular.js/blob/823295f/src/ngResource/resource.js#L489-L490
https://github.com/angular/angular.js/blob/823295f/src/ngRoute/route.js#L28-L30
https://github.com/angular/angular.js/blob/823295f/src/ngRoute/route.js#L680-L685
https://github.com/angular/angular.js/blob/823295f/src/ngRoute/route.js#L727-L728
https://github.com/angular/angular.js/blob/823295f/src/ngRoute/route.js#L753-L760
https://github.com/angular/angular.js/blob/823295f/src/ngSanitize/sanitize.js#L110-L116
https://github.com/angular/angular.js/blob/823295f/src/ngSanitize/sanitize.js#L122-L123
https://github.com/angular/angular.js/blob/823295f/src/ngSanitize/sanitize.js#L131-L132
https://github.com/angular/angular.js/blob/823295f/src/ngSanitize/sanitize.js#L423-L433
https://github.com/angular/angular.js/blob/823295f/src/ngSanitize/filter/linky.js#L91-L92
https://github.com/angular/angular.js/blob/823295f/src/ngSanitize/filter/linky.js#L98-L99
https://github.com/angular/angular.js/blob/823295f/src/ngSanitize/filter/linky.js#L107-L108
https://github.com/angular/angular.js/blob/823295f/src/ngSanitize/filter/linky.js#L115-L117
https://github.com/angular/angular.js/blob/823295f/src/ngSanitize/filter/linky.js#L122-L124
https://github.com/angular/angular.js/blob/823295f/src/ngSanitize/filter/linky.js#L752-L755
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh well...