From e524652273f6419c692fdebe172168e8ad0a1c75 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Wed, 18 Apr 2018 15:42:33 +0200 Subject: [PATCH] go a little slower on well-defined errors, #47475 --- src/vs/platform/files/common/files.ts | 13 ++--- src/vs/vscode.proposed.d.ts | 55 ++++++++++--------- .../electron-browser/mainThreadFileSystem.ts | 10 +++- .../electron-browser/remoteFileService.ts | 4 +- 4 files changed, 43 insertions(+), 39 deletions(-) diff --git a/src/vs/platform/files/common/files.ts b/src/vs/platform/files/common/files.ts index cab1972b2e0..0c4dbfe44af 100644 --- a/src/vs/platform/files/common/files.ts +++ b/src/vs/platform/files/common/files.ts @@ -158,14 +158,13 @@ export enum FileType2 { export class FileError extends Error { + static readonly EntryExists = new FileError('EEXIST'); + static readonly EntryNotFound = new FileError('ENOENT'); + static readonly EntryNotADirectory = new FileError('ENOTDIR'); + static readonly EntryIsADirectory = new FileError('EISDIR'); - static readonly EEXIST = new FileError('EEXIST'); - static readonly ENOENT = new FileError('ENOENT'); - static readonly ENOTDIR = new FileError('ENOTDIR'); - static readonly EISDIR = new FileError('EISDIR'); - - constructor(readonly code: string) { - super(code); + constructor(readonly code: string, message?: string) { + super(message || code); } is(err: any): err is FileError { if (!err || typeof err !== 'object') { diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 6bf0f87445f..ab7e16db4ce 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -172,32 +172,32 @@ declare module 'vscode' { // create(resource: Uri): Thenable; } - export class FileError extends Error { + // export class FileError extends Error { - /** - * Entry already exists. - */ - static readonly EEXIST: FileError; + // /** + // * Entry already exists, e.g. when creating a file or folder. + // */ + // static readonly EntryExists: FileError; - /** - * Entry does not exist. - */ - static readonly ENOENT: FileError; + // /** + // * Entry does not exist. + // */ + // static readonly EntryNotFound: FileError; - /** - * Entry is not a directory. - */ - static readonly ENOTDIR: FileError; + // /** + // * Entry is not a directory. + // */ + // static readonly EntryNotADirectory: FileError; - /** - * Entry is a directory. - */ - static readonly EISDIR: FileError; + // /** + // * Entry is a directory. + // */ + // static readonly EntryIsADirectory: FileError; - readonly code: string; + // readonly code: string; - constructor(code: string, message?: string); - } + // constructor(code: string, message?: string); + // } export enum FileChangeType2 { Changed = 1, @@ -229,7 +229,9 @@ declare module 'vscode' { Exclusive = 0b1000 } - // todo@joh add open/close calls? + /** + * + */ export interface FileSystemProvider2 { _version: 7; @@ -242,15 +244,14 @@ declare module 'vscode' { readonly onDidChangeFile: Event; /** - * Subscribe to events in the file or folder denoted by `uri`. - * @param uri - * @param options + * Subscribe to events in the file or folder denoted by `uri`. + * @param uri + * @param options */ watch(uri: Uri, options: { recursive?: boolean; excludes?: string[] }): Disposable; /** - * Retrieve metadata about a file. Must throw an [`ENOENT`](#FileError.ENOENT)-error - * when the file doesn't exist. + * Retrieve metadata about a file. * * @param uri The uri of the file to retrieve meta data about. * @param token A cancellation token. @@ -269,7 +270,7 @@ declare module 'vscode' { /** * Create a new directory. *Note* that new files are created via `write`-calls. - * + * * @param uri The uri of the *new* folder. * @param token A cancellation token. */ diff --git a/src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts b/src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts index 0a9f3485f76..f62ded3f536 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts @@ -8,7 +8,7 @@ import { Emitter, Event } from 'vs/base/common/event'; import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import URI from 'vs/base/common/uri'; import { TPromise } from 'vs/base/common/winjs.base'; -import { FileOpenFlags, IFileChange, IFileService, IFileSystemProviderBase, ISimpleReadWriteProvider, IStat, IWatchOptions } from 'vs/platform/files/common/files'; +import { FileOpenFlags, IFileChange, IFileService, IFileSystemProviderBase, ISimpleReadWriteProvider, IStat, IWatchOptions, FileError } from 'vs/platform/files/common/files'; import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers'; import { ExtHostContext, ExtHostFileSystemShape, IExtHostContext, IFileChangeDto, MainContext, MainThreadFileSystemShape } from '../node/extHost.protocol'; @@ -86,8 +86,10 @@ class RemoteFileSystemProvider implements ISimpleReadWriteProvider, IFileSystemP // --- forwarding calls - stat(resource: URI): TPromise { - return this._proxy.$stat(this._handle, resource); + stat(resource: URI): TPromise { + return this._proxy.$stat(this._handle, resource).then(undefined, err => { + throw err; + }); } readFile(resource: URI, opts: { flags: FileOpenFlags }): TPromise { return this._proxy.$readFile(this._handle, resource, opts.flags).then(encoded => { @@ -112,4 +114,6 @@ class RemoteFileSystemProvider implements ISimpleReadWriteProvider, IFileSystemP readdir(resource: URI): TPromise<[string, IStat][], any> { return this._proxy.$readdir(this._handle, resource); } + + } diff --git a/src/vs/workbench/services/files/electron-browser/remoteFileService.ts b/src/vs/workbench/services/files/electron-browser/remoteFileService.ts index 322e173fddc..b7143cff479 100644 --- a/src/vs/workbench/services/files/electron-browser/remoteFileService.ts +++ b/src/vs/workbench/services/files/electron-browser/remoteFileService.ts @@ -369,8 +369,8 @@ export class RemoteFileService extends FileService { this._onAfterOperation.fire(new FileOperationEvent(resource, FileOperation.CREATE, fileStat)); return fileStat; }, err => { - if (FileError.EEXIST.is(err)) { - return TPromise.wrapError(new FileOperationError('EEXIST', FileOperationResult.FILE_MODIFIED_SINCE, options)); + if (FileError.EntryExists.is(err)) { + return TPromise.wrapError(new FileOperationError(err.code, FileOperationResult.FILE_MODIFIED_SINCE, options)); } throw err; }); -- GitLab