nuke TPromise error handling #53526

This commit is contained in:
Johannes Rieken 2018-12-12 17:09:28 +01:00
parent 3d675f8170
commit 4161bfc71d

View file

@ -3,59 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { TPromise, IPromiseError, IPromiseErrorDetail } from 'vs/base/common/winjs.base';
// ------ BEGIN Hook up error listeners to winjs promises
let outstandingPromiseErrors: { [id: string]: IPromiseErrorDetail; } = {};
function promiseErrorHandler(e: IPromiseError): void {
//
// e.detail looks like: { exception, error, promise, handler, id, parent }
//
const details = e.detail;
const id = details.id;
// If the error has a parent promise then this is not the origination of the
// error so we check if it has a handler, and if so we mark that the error
// was handled by removing it from outstandingPromiseErrors
//
if (details.parent) {
if (details.handler && outstandingPromiseErrors) {
delete outstandingPromiseErrors[id];
}
return;
}
// Indicate that this error was originated and needs to be handled
outstandingPromiseErrors[id] = details;
// The first time the queue fills up this iteration, schedule a timeout to
// check if any errors are still unhandled.
if (Object.keys(outstandingPromiseErrors).length === 1) {
setTimeout(function () {
const errors = outstandingPromiseErrors;
outstandingPromiseErrors = {};
Object.keys(errors).forEach(function (errorId) {
const error = errors[errorId];
if (error.exception) {
onUnexpectedError(error.exception);
} else if (error.error) {
onUnexpectedError(error.error);
}
console.log('WARNING: Promise with no error callback:' + error.id);
console.log(error);
if (error.exception) {
console.log(error.exception.stack);
}
});
}, 0);
}
}
TPromise.addEventListener('error', promiseErrorHandler);
// ------ END Hook up error listeners to winjs promises
export interface ErrorListenerCallback {
(error: any): void;
}