提交 e5246522 编写于 作者: J Johannes Rieken

go a little slower on well-defined errors, #47475

上级 fbdc0496
......@@ -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') {
......
......@@ -172,32 +172,32 @@ declare module 'vscode' {
// create(resource: Uri): Thenable<FileStat>;
}
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<FileChange2[]>;
/**
* 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.
*/
......
......@@ -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<IStat, any> {
return this._proxy.$stat(this._handle, resource);
stat(resource: URI): TPromise<IStat, FileError> {
return this._proxy.$stat(this._handle, resource).then(undefined, err => {
throw err;
});
}
readFile(resource: URI, opts: { flags: FileOpenFlags }): TPromise<Uint8Array, any> {
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);
}
}
......@@ -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;
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册