From 76a28be0f2a1835965cd69441a67fe1bab5d56c2 Mon Sep 17 00:00:00 2001 From: Kelvin Schoofs Date: Thu, 2 Jun 2022 19:01:46 +0200 Subject: [PATCH] Add `DEBUG_FS` flag with extra ignored paths (fixes #341) --- CHANGELOG.md | 3 +++ src/config.ts | 8 ++++++++ src/sshFileSystem.ts | 25 ++++++++++++++++++++----- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14fc488..7dccd18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ - Currently, this makes it that changing the global flags can immediately have an effect for some flags - Global flags are those defined in your User Settings or Workspace(Folder) Settings - Mind that if you override those flags by specifying them in your SSH FS config, it'll keep using them +- Added the `DEBUG_FS` flag to allow enabling detailed conditional logging in `sshFileSystem` (#341) + - This flag will auto-update when it changes in global flags, unless it's overriden in your SSH FS config + - Mostly meant for internal debugging or helping with debugging specific user-reported issues ## v1.25.0 (2022-06-01) diff --git a/src/config.ts b/src/config.ts index 2095c3c..8308722 100644 --- a/src/config.ts +++ b/src/config.ts @@ -386,6 +386,14 @@ function parseFlagList(list: string[] | undefined, origin: string): Record entry === target || entry.endsWith('/') && target.startsWith(entry))) return true; @@ -36,6 +38,7 @@ function shouldIgnoreNotFound(target: string) { export class SSHFileSystem implements vscode.FileSystemProvider { protected onCloseEmitter = new vscode.EventEmitter(); protected onDidChangeFileEmitter = new vscode.EventEmitter(); + protected debugFlags: string[]; public closed = false; public closing = false; public copy = undefined; @@ -46,6 +49,11 @@ export class SSHFileSystem implements vscode.FileSystemProvider { this.logging = Logging.scope(`SSHFileSystem(${authority})`, false); this.sftp.on('end', () => (this.closed = true, this.onCloseEmitter.fire())); this.logging.info('SSHFileSystem created'); + const subscription = subscribeToGlobalFlags(() => { + this.debugFlags = `${getFlag('DEBUG_FS', this.config.flags)?.[0] || ''}`.toLowerCase().split(/,\s*|\s+/g); + if (this.debugFlags.includes('all')) this.debugFlags.push('ignoredmissing', 'full', 'missing', 'converted'); + }); + this.onClose(() => subscription.dispose()); } public disconnect() { this.closing = true; @@ -162,11 +170,17 @@ export class SSHFileSystem implements vscode.FileSystemProvider { 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, ...) - const flags = `${ignore[0] ? 'F' : ''}${ignore[1] ? 'A' : ''}`; - this.logging.debug(`Ignored (${flags}) FileNotFound error for: ${uri}`, LOGGING_NO_STACKTRACE); + if (this.debugFlags.includes('ignoredmissing')) { + 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}`; + else if (this.debugFlags.includes('full')) { + this.logging.debug.withOptions(LOGGING_HANDLE_ERROR)`Error in ${uri}: ${e}`; + } else if (this.debugFlags.includes('minimal')) { + this.logging.debug.withOptions({ ...LOGGING_NO_STACKTRACE, maxErrorStack: 0 })`Error in ${uri}: ${e.name}: ${e.message}`; + } // Convert SSH2Stream error codes into VS Code errors if (doThrow && typeof e.code === 'number') { const oldE = e; @@ -179,7 +193,8 @@ export class SSHFileSystem implements vscode.FileSystemProvider { } else if (e.code === 7) { // Connection lost e = vscode.FileSystemError.Unavailable(uri); } - if (e !== oldE) Logging.debug(`Error converted to: ${e}`); + if (e !== oldE && this.debugFlags.includes('converted')) + Logging.debug(`Error converted to: ${e}`); } // Display an error notification if the FS_ERROR_NOTIFICATION flag is enabled const [flagCH] = getFlagBoolean('FS_NOTIFY_ERRORS', true, this.config.flags);