support user data error handling

This commit is contained in:
Sandeep Somavarapu
2019-09-10 17:32:02 +02:00
parent cc0f39133b
commit be01168e52
6 changed files with 75 additions and 6 deletions

View File

@@ -897,7 +897,8 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
// proposed
CallHierarchyDirection: extHostTypes.CallHierarchyDirection,
CallHierarchyItem: extHostTypes.CallHierarchyItem,
Decoration: extHostTypes.Decoration
Decoration: extHostTypes.Decoration,
UserDataError: extHostTypes.UserDataError
};
};
}

View File

@@ -14,6 +14,7 @@ import { generateUuid } from 'vs/base/common/uuid';
import * as vscode from 'vscode';
import { FileSystemProviderErrorCode, markAsFileSystemProviderError } from 'vs/platform/files/common/files';
import { RemoteAuthorityResolverErrorCode } from 'vs/platform/remote/common/remoteAuthorityResolver';
import { RemoteUserDataErrorCode, markAsUserDataError } from 'vs/workbench/services/userData/common/userData';
function es5ClassCompat(target: Function): any {
///@ts-ignore
@@ -2367,3 +2368,25 @@ export class Decoration {
priority?: number;
bubble?: boolean;
}
@es5ClassCompat
export class UserDataError extends Error {
static VersionExists(message?: string): UserDataError {
return new UserDataError(message, RemoteUserDataErrorCode.VersionExists);
}
constructor(message?: string, code: RemoteUserDataErrorCode = RemoteUserDataErrorCode.Unknown) {
super(message);
// mark the error as user data provider error so that
// we can extract the error code on the receiving side
markAsUserDataError(this, code);
// workaround when extending builtin objects and when compiling to ES5, see:
// https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
if (typeof (<any>Object).setPrototypeOf === 'function') {
(<any>Object).setPrototypeOf(this, UserDataError.prototype);
}
}
}