Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
/angular.jsPublic archive

Commit6e2531b

Browse files
author
Thomas Grainger
committed
Add traceback to unhandled promise rejections,Fixes:#14631
1 parent4e143fc commit6e2531b

File tree

2 files changed

+65
-40
lines changed

2 files changed

+65
-40
lines changed

‎src/ng/q.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,11 @@ function qFactory(nextTick, exceptionHandler, errorOnUnhandledRejections) {
381381
if(!toCheck.pur){
382382
toCheck.pur=true;
383383
varerrorMessage='Possibly unhandled rejection: '+toDebugString(toCheck.value);
384-
exceptionHandler(errorMessage);
384+
if(toCheck.valueinstanceofError){
385+
exceptionHandler(toCheck.value,errorMessage);
386+
}else{
387+
exceptionHandler(errorMessage);
388+
}
385389
}
386390
}
387391
}

‎test/ng/qSpec.js

Lines changed: 60 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,14 @@ describe('q', function() {
181181
};
182182

183183

184-
functionexceptionHandler(reason){
185-
exceptionHandlerCalls.push(reason);
186-
}
187-
188-
189-
functionexceptionHandlerStr(){
190-
returnexceptionHandlerCalls.join('; ');
184+
functionexceptionHandler(exception,reason){
185+
if(typeofreason===undefined){
186+
exceptionHandlerCalls.push({reason:exception});
187+
}else{
188+
exceptionHandlerCalls.push({reason:reason,exception:exception});
189+
}
191190
}
192191

193-
194192
beforeEach(function(){
195193
q=qFactory(mockNextTick.nextTick,exceptionHandler,true);
196194
q_no_error=qFactory(mockNextTick.nextTick,exceptionHandler,false);
@@ -2167,45 +2165,68 @@ describe('q', function() {
21672165

21682166

21692167
describe('when exceptionHandler is called',function(){
2170-
it('should log an unhandled rejected promise',function(){
2171-
vardefer=q.defer();
2172-
defer.reject('foo');
2173-
mockNextTick.flush();
2174-
expect(exceptionHandlerStr()).toBe('Possibly unhandled rejection: foo');
2175-
});
2168+
varexceptionEg=newError('Fail');
2169+
varfixtures=[
2170+
{
2171+
type:'exception',
2172+
value:exceptionEg,
2173+
expected:{
2174+
exception:exceptionEg,
2175+
reason:'Possibly unhanlded rejction: Error: Fail'
2176+
};
2177+
},
2178+
{
2179+
type:'plain value',
2180+
value:'foo',
2181+
expected:{
2182+
reason:'Possibly unhandled rejection: foo'
2183+
}
2184+
}
2185+
];
2186+
forEach(fixtures,function(fixture){
2187+
vartype=fixture.type;
2188+
varvalue=fixture.value;
2189+
varexpected=fixture.expected;
2190+
it('should log an unhandled'+type+' rejected promise',function(){
2191+
vardefer=q.defer();
2192+
defer.reject(value);
2193+
mockNextTick.flush();
2194+
expect(exceptionHandlerCalls).toEqual([expected]);
2195+
});
21762196

21772197

2178-
it('should not log an unhandled rejected promise if disabled',function(){
2179-
vardefer=q_no_error.defer();
2180-
defer.reject('foo');
2181-
expect(exceptionHandlerStr()).toBe('');
2182-
});
2198+
it('should not log an unhandled'+type+' rejected promise if disabled',function(){
2199+
vardefer=q_no_error.defer();
2200+
defer.reject(value);
2201+
expect(exceptionHandlerCalls).toEqual([]);
2202+
});
21832203

21842204

2185-
it('should log a handled rejected promise on a promise without rejection callbacks',function(){
2186-
vardefer=q.defer();
2187-
defer.promise.then(noop);
2188-
defer.reject('foo');
2189-
mockNextTick.flush();
2190-
expect(exceptionHandlerStr()).toBe('Possibly unhandled rejection: foo');
2191-
});
2205+
it('should log a handled'+type+' rejected promise on a promise without rejection callbacks',function(){
2206+
vardefer=q.defer();
2207+
defer.promise.then(noop);
2208+
defer.reject(value);
2209+
mockNextTick.flush();
2210+
expect(exceptionHandlerCalls).toEqual([expected]);
2211+
});
21922212

21932213

2194-
it('should not log a handledrejected promise',function(){
2195-
vardefer=q.defer();
2196-
defer.promise.catch(noop);
2197-
defer.reject('foo');
2198-
mockNextTick.flush();
2199-
expect(exceptionHandlerStr()).toBe('');
2200-
});
2214+
it('should not log a handled'+type+'rejected promise',function(){
2215+
vardefer=q.defer();
2216+
defer.promise.catch(noop);
2217+
defer.reject(value);
2218+
mockNextTick.flush();
2219+
expect(exceptionHandlerCalls).toEqual([]);
2220+
});
22012221

22022222

2203-
it('should not log a handled rejected promise that is handled in a future tick',function(){
2204-
vardefer=q.defer();
2205-
defer.promise.catch(noop);
2206-
defer.resolve(q.reject('foo'));
2207-
mockNextTick.flush();
2208-
expect(exceptionHandlerStr()).toBe('');
2223+
it('should not log a handled'+type+' rejected promise that is handled in a future tick',function(){
2224+
vardefer=q.defer();
2225+
defer.promise.catch(noop);
2226+
defer.resolve(q.reject(value));
2227+
mockNextTick.flush();
2228+
expect(exceptionHandlerCalls).toEqual([]);
2229+
});
22092230
});
22102231
});
22112232
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp