Skip to content

Commit

Permalink
Auto-silence FileNotFound erors for stat (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoofsKelvin committed May 31, 2022
1 parent e95c16a commit dc20709
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
- This solves a small issue/annoyance where logs regarding loading logs appear before the version logging
- When `${workingDirectory}` is present in a terminal command, the extension doesn't auto-`cd` anymore
- Normally the extension runs `cd <workingDirectory>; <terminalCommand>` or similar
- Auto-silence FileNotFound erors for stat (#334)
- The extension will no longer show notification bubbles for failed `stat` operations due to non-existing files

### Development changes
- Added `semver` as dependency in preparation of `FS_NOTIFY_ERRORS` flag
Expand Down
10 changes: 6 additions & 4 deletions src/sshFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class SSHFileSystem implements vscode.FileSystemProvider {
}
public async stat(uri: vscode.Uri): Promise<vscode.FileStat> {
const stat = await toPromise<ssh2.sftp.Stats>(cb => this.sftp.stat(uri.path, cb))
.catch(e => this.handleError(uri, e, true) as never);
.catch(e => this.handleError(uri, e, true, true) as never);
const { mtime = 0, size = 0 } = stat;
let type = vscode.FileType.Unknown;
// tslint:disable no-bitwise */
Expand Down Expand Up @@ -156,12 +156,14 @@ export class SSHFileSystem implements vscode.FileSystemProvider {
.catch(e => this.handleError(newUri, e, true));
}
// Helper function to handle/report errors with proper (and minimal) stacktraces and such
protected handleError(uri: vscode.Uri, e: Error & { code?: any }, doThrow: (boolean | ((error: any) => void)) = false): any {
if (e.code === 2 && shouldIgnoreNotFound(uri.path)) {
protected handleError(uri: vscode.Uri, e: Error & { code?: any }, doThrow: (boolean | ((error: any) => void)) = false, ignoreNotFound = false): any {
const ignore = e.code === 2 && [ignoreNotFound, shouldIgnoreNotFound(uri.path)];
if (ignore && ignore.includes(true)) {
e = vscode.FileSystemError.FileNotFound(uri);
// Whenever a workspace opens, VSCode (and extensions) (indirectly) stat a bunch of files
// (.vscode/tasks.json etc, .git/, node_modules for NodeJS, pom.xml for Maven, ...)
this.logging.debug(`Ignored FileNotFound error for: ${uri}`, LOGGING_NO_STACKTRACE);
const flags = `${ignore[0] ? 'F' : ''}${ignore[1] ? 'A' : ''}`;
this.logging.debug(`Ignored (${flags}) FileNotFound error for: ${uri}`, LOGGING_NO_STACKTRACE);
if (doThrow === true) throw e; else if (doThrow) return doThrow(e); else return;
}
Logging.error.withOptions(LOGGING_HANDLE_ERROR)`Error handling uri: ${uri}\n${e}`;
Expand Down

0 comments on commit dc20709

Please sign in to comment.