diff --git a/CHANGELOG.md b/CHANGELOG.md index de6eca0..316cdb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ; ` 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 diff --git a/src/sshFileSystem.ts b/src/sshFileSystem.ts index 6f8de29..d0263c3 100644 --- a/src/sshFileSystem.ts +++ b/src/sshFileSystem.ts @@ -58,7 +58,7 @@ export class SSHFileSystem implements vscode.FileSystemProvider { } public async stat(uri: vscode.Uri): Promise { const stat = await toPromise(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 */ @@ -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}`;