Skip to content

Commit 5410d71

Browse files
author
Benjamin Pasero
committed
💄 file service errors
1 parent 9349e9a commit 5410d71

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

src/vs/platform/files/common/fileService.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class FileService extends Disposable implements IFileService {
4646

4747
registerProvider(scheme: string, provider: IFileSystemProvider): IDisposable {
4848
if (this.provider.has(scheme)) {
49-
throw new Error(`A provider for the scheme ${scheme} is already registered.`);
49+
throw new Error(`A filesystem provider for the scheme '${scheme}' is already registered.`);
5050
}
5151

5252
// Add provider with event
@@ -106,7 +106,7 @@ export class FileService extends Disposable implements IFileService {
106106

107107
// Assert path is absolute
108108
if (!isAbsolutePath(resource)) {
109-
throw new FileOperationError(localize('invalidPath', "The path of resource '{0}' must be absolute", this.resourceForError(resource)), FileOperationResult.FILE_INVALID_PATH);
109+
throw new FileOperationError(localize('invalidPath', "Unable to resolve filesystem provider with relative file path '{0}'", this.resourceForError(resource)), FileOperationResult.FILE_INVALID_PATH);
110110
}
111111

112112
// Activate provider
@@ -132,7 +132,7 @@ export class FileService extends Disposable implements IFileService {
132132
return provider;
133133
}
134134

135-
throw new Error(`Provider for scheme '${resource.scheme}' neither has FileReadWrite, FileReadStream nor FileOpenReadWriteClose capability which is needed for the read operation.`);
135+
throw new Error(`Filesystem provider for scheme '${resource.scheme}' neither has FileReadWrite, FileReadStream nor FileOpenReadWriteClose capability which is needed for the read operation.`);
136136
}
137137

138138
private async withWriteProvider(resource: URI): Promise<IFileSystemProviderWithFileReadWriteCapability | IFileSystemProviderWithOpenReadWriteCloseCapability> {
@@ -142,7 +142,7 @@ export class FileService extends Disposable implements IFileService {
142142
return provider;
143143
}
144144

145-
throw new Error(`Provider for scheme '${resource.scheme}' neither has FileReadWrite nor FileOpenReadWriteClose capability which is needed for the write operation.`);
145+
throw new Error(`Filesystem provider for scheme '${resource.scheme}' neither has FileReadWrite nor FileOpenReadWriteClose capability which is needed for the write operation.`);
146146
}
147147

148148
//#endregion
@@ -164,7 +164,7 @@ export class FileService extends Disposable implements IFileService {
164164

165165
// Specially handle file not found case as file operation result
166166
if (toFileSystemProviderErrorCode(error) === FileSystemProviderErrorCode.FileNotFound) {
167-
throw new FileOperationError(localize('fileNotFoundError', "File not found ({0})", this.resourceForError(resource)), FileOperationResult.FILE_NOT_FOUND);
167+
throw new FileOperationError(localize('fileNotFoundError', "Unable to resolve non-existing file '{0}'", this.resourceForError(resource)), FileOperationResult.FILE_NOT_FOUND);
168168
}
169169

170170
// Bubble up any other error as is
@@ -292,7 +292,7 @@ export class FileService extends Disposable implements IFileService {
292292

293293
// validate overwrite
294294
if (!options?.overwrite && await this.exists(resource)) {
295-
throw new FileOperationError(localize('fileExists', "File to create already exists ({0})", this.resourceForError(resource)), FileOperationResult.FILE_MODIFIED_SINCE, options);
295+
throw new FileOperationError(localize('fileExists', "Unable to create file '{0}' that already exists when overwrite flag is not set", this.resourceForError(resource)), FileOperationResult.FILE_MODIFIED_SINCE, options);
296296
}
297297

298298
// do write into file (this will create it too)
@@ -355,7 +355,7 @@ export class FileService extends Disposable implements IFileService {
355355

356356
// file cannot be directory
357357
if ((stat.type & FileType.Directory) !== 0) {
358-
throw new FileOperationError(localize('fileIsDirectoryError', "Expected file '{0}' is actually a directory", this.resourceForError(resource)), FileOperationResult.FILE_IS_DIRECTORY, options);
358+
throw new FileOperationError(localize('fileIsDirectoryWriteError', "Unable to write file '{0}' that is actually a directory", this.resourceForError(resource)), FileOperationResult.FILE_IS_DIRECTORY, options);
359359
}
360360

361361
// Dirty write prevention: if the file on disk has been changed and does not match our expected
@@ -504,7 +504,7 @@ export class FileService extends Disposable implements IFileService {
504504

505505
// Throw if resource is a directory
506506
if (stat.isDirectory) {
507-
throw new FileOperationError(localize('fileIsDirectoryError', "Expected file '{0}' is actually a directory", this.resourceForError(resource)), FileOperationResult.FILE_IS_DIRECTORY, options);
507+
throw new FileOperationError(localize('fileIsDirectoryReadError', "Unable to read file '{0}' that is actually a directory", this.resourceForError(resource)), FileOperationResult.FILE_IS_DIRECTORY, options);
508508
}
509509

510510
// Throw if file not modified since (unless disabled)
@@ -531,7 +531,7 @@ export class FileService extends Disposable implements IFileService {
531531
}
532532

533533
if (typeof tooLargeErrorResult === 'number') {
534-
throw new FileOperationError(localize('fileTooLargeError', "File '{0}' is too large to open", this.resourceForError(resource)), tooLargeErrorResult);
534+
throw new FileOperationError(localize('fileTooLargeError', "Unable to read file '{0}' that is too large to open", this.resourceForError(resource)), tooLargeErrorResult);
535535
}
536536
}
537537
}
@@ -693,15 +693,15 @@ export class FileService extends Disposable implements IFileService {
693693

694694
// Bail out if target exists and we are not about to overwrite
695695
if (!overwrite) {
696-
throw new FileOperationError(localize('unableToMoveCopyError3', "Unable to move/copy since a file already exists at destination."), FileOperationResult.FILE_MOVE_CONFLICT);
696+
throw new FileOperationError(localize('unableToMoveCopyError3', "Unable to move/copy '{0}' because target '{1}' already exists at destination.", this.resourceForError(source), this.resourceForError(target)), FileOperationResult.FILE_MOVE_CONFLICT);
697697
}
698698

699699
// Special case: if the target is a parent of the source, we cannot delete
700700
// it as it would delete the source as well. In this case we have to throw
701701
if (sourceProvider === targetProvider) {
702702
const isPathCaseSensitive = !!(sourceProvider.capabilities & FileSystemProviderCapabilities.PathCaseSensitive);
703703
if (isEqualOrParent(source, target, !isPathCaseSensitive)) {
704-
throw new Error(localize('unableToMoveCopyError4', "Unable to move/copy since a file would replace the folder it is contained in."));
704+
throw new Error(localize('unableToMoveCopyError4', "Unable to move/copy '{0}' into '{1}' since a file would replace the folder it is contained in.", this.resourceForError(source), this.resourceForError(target)));
705705
}
706706
}
707707
}
@@ -730,7 +730,7 @@ export class FileService extends Disposable implements IFileService {
730730
try {
731731
const stat = await provider.stat(directory);
732732
if ((stat.type & FileType.Directory) === 0) {
733-
throw new Error(localize('mkdirExistsError', "Path '{0}' already exists, but is not a directory", this.resourceForError(directory)));
733+
throw new Error(localize('mkdirExistsError', "Unable to create folder '{0}' that already exists but is not a directory", this.resourceForError(directory)));
734734
}
735735

736736
break; // we have hit a directory that exists -> good
@@ -762,21 +762,21 @@ export class FileService extends Disposable implements IFileService {
762762
// Validate trash support
763763
const useTrash = !!options?.useTrash;
764764
if (useTrash && !(provider.capabilities & FileSystemProviderCapabilities.Trash)) {
765-
throw new Error(localize('err.trash', "Provider for scheme '{0}' does not support trash.", resource.scheme));
765+
throw new Error(localize('deleteFailedTrashUnsupported', "Unable to delete file '{0}' via trash because provider does not support it.", this.resourceForError(resource)));
766766
}
767767

768768
// Validate delete
769769
const exists = await this.exists(resource);
770770
if (!exists) {
771-
throw new FileOperationError(localize('fileNotFoundError', "File not found ({0})", this.resourceForError(resource)), FileOperationResult.FILE_NOT_FOUND);
771+
throw new FileOperationError(localize('deleteFailedNotFound', "Unable to delete non-existing file '{0}'", this.resourceForError(resource)), FileOperationResult.FILE_NOT_FOUND);
772772
}
773773

774774
// Validate recursive
775775
const recursive = !!options?.recursive;
776776
if (!recursive && exists) {
777777
const stat = await this.resolve(resource);
778778
if (stat.isDirectory && Array.isArray(stat.children) && stat.children.length > 0) {
779-
throw new Error(localize('deleteFailed', "Unable to delete non-empty folder '{0}'.", this.resourceForError(resource)));
779+
throw new Error(localize('deleteFailedNonEmptyFolder', "Unable to delete non-empty folder '{0}'.", this.resourceForError(resource)));
780780
}
781781
}
782782

@@ -1059,7 +1059,7 @@ export class FileService extends Disposable implements IFileService {
10591059

10601060
protected throwIfFileSystemIsReadonly<T extends IFileSystemProvider>(provider: T, resource: URI): T {
10611061
if (provider.capabilities & FileSystemProviderCapabilities.Readonly) {
1062-
throw new FileOperationError(localize('err.readonly', "Resource '{0}' can not be modified.", this.resourceForError(resource)), FileOperationResult.FILE_PERMISSION_DENIED);
1062+
throw new FileOperationError(localize('err.readonly', "Unable to modify readonly file '{0}'", this.resourceForError(resource)), FileOperationResult.FILE_PERMISSION_DENIED);
10631063
}
10641064

10651065
return provider;

0 commit comments

Comments
 (0)