Skip to content

Add error code getter to FileSystemError #90517#90586

Merged
jrieken merged 1 commit intomicrosoft:masterfrom
iliazeus:90517-file-system-error-code
Mar 6, 2020
Merged

Add error code getter to FileSystemError #90517#90586
jrieken merged 1 commit intomicrosoft:masterfrom
iliazeus:90517-file-system-error-code

Conversation

@iliazeus
Copy link
Contributor

This PR fixes #90517

The only way I found in the current source to extract the error code from a FileSystemError is through calling toFileSystemProviderErrorCode(). This PR exposes that ability to extensions through a getter on class FileSystemError.

@msftclas
Copy link

msftclas commented Feb 13, 2020

CLA assistant check
All CLA requirements met.

@jrieken
Copy link
Member

jrieken commented Feb 13, 2020

👎 this duplicates information that's already available in the ctor. To know what kind of error happened you can use an instanceof-check or the ctor-name if you like.

@jrieken jrieken self-assigned this Feb 13, 2020
Copy link
Member

@jrieken jrieken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment

@iliazeus
Copy link
Contributor Author

👎 this duplicates information that's already available in the ctor. To know what kind of error happened you can use an instanceof-check or the ctor-name if you like.

It seems that there's no information in the prototype chain about the specific kind of filesystem error (file not found/no permissions/etc.).

https://github.com/microsoft/vscode/blob/master/src/vs/workbench/api/common/extHostTypes.ts#L2305

Are you suggesting subclassing FileSystemError for each specific type, making its static methods return the appropriate subclasses, and expose the subclasses through the api?

@jrieken
Copy link
Member

jrieken commented Feb 14, 2020

Are you suggesting subclassing FileSystemError for each specific type, making its static methods return the appropriate subclasses, and expose the subclasses through the api?

Oh, I am sorry. I thought we already had that... Now your PR makes much more sense but I would keep it more minimal tbh. How about using the code-argument as name of the error, like this.name = code. That would be minimal and should be sufficient.

@iliazeus
Copy link
Contributor Author

this.name is already being set by markAsFileSystemProviderError(). And toFileSystemProviderErorrCode() just tries to parse that to tell what happened exactly.

https://github.com/microsoft/vscode/blob/master/src/vs/platform/files/common/files.ts#L346

In an extension, I could just parse error.name myself, but the API does not currently specify its contents. That is, I would somehow have to know that error.name should include EntryNotFound for a "not found" error (and not FileNotFound).

@jrieken
Copy link
Member

jrieken commented Feb 21, 2020

What I don't like that those names - they are internal and don't make much sense in the API, like the error code for FileNotFound is EntryNotFound... So, I'd suggest to simply use the tor-function names, no string-enum or anything just something like this

export class FileSystemError extends Error {
  //...
  /**
   * A code that identifies this error. The value is equal to 
   * the (class) name of the error, e.g `FileNotFound`.
   */
  readonly code: string
}

@iliazeus iliazeus requested a review from jrieken February 25, 2020 09:55
@jrieken jrieken added this to the March 2020 milestone Feb 25, 2020
@iliazeus
Copy link
Contributor Author

iliazeus commented Mar 6, 2020

I've also found some FileSystemError ctor calls in KeyValueLogProvider.ts:

return Promise.reject(new FileSystemError(resource, FileSystemProviderErrorCode.FileNotADirectory));

I've changed them to appropriate factory function calls, so the code property is initialized.

https://github.com/microsoft/vscode/blob/2c00388d2d00342347a6a51e6b09649fd2cb6103/src/vs/workbench/services/log/common/keyValueLogProvider.ts#L62

@iliazeus iliazeus requested a review from jrieken March 6, 2020 12:35
};
}
return Promise.reject(new FileSystemError(resource, FileSystemProviderErrorCode.FileNotFound));
return Promise.reject(FileSystemError.FileNotFound(resource));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi @sandy081 but also 🙅‍♂ no good usage of API types inside the core. This shouldn't be like that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. Could be a copy/paste issue. Fixed and used proper fs errors.

@jrieken
Copy link
Member

jrieken commented Mar 6, 2020

Thanks @iliazeus. I'll merge and drive this as api-proposal to finalization

@jrieken jrieken merged commit 0721bf1 into microsoft:master Mar 6, 2020
@iliazeus iliazeus deleted the 90517-file-system-error-code branch March 6, 2020 15:44
@github-actions github-actions bot locked and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add error code getter to FileSystemError

4 participants