Add `DEBUG_FS` flag with extra ignored paths (fixes #341)

pull/373/head
Kelvin Schoofs 2 years ago
parent 1fb7a525e8
commit 76a28be0f2

@ -8,6 +8,9 @@
- Currently, this makes it that changing the global flags can immediately have an effect for some flags - 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 - 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 - 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) ## v1.25.0 (2022-06-01)

@ -386,6 +386,14 @@ function parseFlagList(list: string[] | undefined, origin: string): Record<strin
- Enables attempting to inject a file to be sourced by the remote shells (which adds the `code` alias) - Enables attempting to inject a file to be sourced by the remote shells (which adds the `code` alias)
DEBUG_REMOTE_COMMANDS (boolean) (default=false) DEBUG_REMOTE_COMMANDS (boolean) (default=false)
- Enables debug logging for the remote command terminal (thus useless if REMOTE_COMMANDS isn't true) - Enables debug logging for the remote command terminal (thus useless if REMOTE_COMMANDS isn't true)
DEBUG_FS (string) (default='')
- A comma-separated list of debug flags for logging errors in the sshFileSystem
- The presence of `ignoredmissing` will log `FileNotFound` that got ignored
- The presence of `minimal` will log all errors as single lines, but not `FileNotFound`
- The presence of `full` is the same as `minimal` but with full stacktraces
- The presence of `missing` will log `FileNotFound` errors in `minimal` and `full` (except `ignoredmissing` ones)
- The presence of `converted` will log the resulting converted errors (if required and successful)
- The presence of `all` enables all of the above (similar to `ignoredmissing,full,missing,converted,reads`)
FS_NOTIFY_ERRORS (boolean) (default=false) FS_NOTIFY_ERRORS (boolean) (default=false)
- Enables displaying error notifications when a file system operation fails and isn't automatically ignored - Enables displaying error notifications when a file system operation fails and isn't automatically ignored
- Automatically enabled VS Code 1.56 and later (see issue #282) - Automatically enabled VS Code 1.56 and later (see issue #282)

@ -3,7 +3,7 @@ import type { FileSystemConfig } from 'common/fileSystemConfig';
import * as path from 'path'; import * as path from 'path';
import type * as ssh2 from 'ssh2'; import type * as ssh2 from 'ssh2';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { getFlagBoolean } from './config'; import { getFlag, getFlagBoolean, subscribeToGlobalFlags } from './config';
import { Logger, Logging, LOGGING_NO_STACKTRACE, LOGGING_SINGLE_LINE_STACKTRACE, withStacktraceOffset } from './logging'; import { Logger, Logging, LOGGING_NO_STACKTRACE, LOGGING_SINGLE_LINE_STACKTRACE, withStacktraceOffset } from './logging';
import { toPromise } from './utils'; import { toPromise } from './utils';
@ -21,6 +21,8 @@ const IGNORE_NOT_FOUND: string[] = [
'/node_modules', '/node_modules',
'/pom.xml', '/pom.xml',
'/app/src/main/AndroidManifest.xml', '/app/src/main/AndroidManifest.xml',
'/build.gradle',
'/.devcontainer/devcontainer.json',
]; ];
function shouldIgnoreNotFound(target: string) { function shouldIgnoreNotFound(target: string) {
if (IGNORE_NOT_FOUND.some(entry => entry === target || entry.endsWith('/') && target.startsWith(entry))) return true; if (IGNORE_NOT_FOUND.some(entry => entry === target || entry.endsWith('/') && target.startsWith(entry))) return true;
@ -36,6 +38,7 @@ function shouldIgnoreNotFound(target: string) {
export class SSHFileSystem implements vscode.FileSystemProvider { export class SSHFileSystem implements vscode.FileSystemProvider {
protected onCloseEmitter = new vscode.EventEmitter<void>(); protected onCloseEmitter = new vscode.EventEmitter<void>();
protected onDidChangeFileEmitter = new vscode.EventEmitter<vscode.FileChangeEvent[]>(); protected onDidChangeFileEmitter = new vscode.EventEmitter<vscode.FileChangeEvent[]>();
protected debugFlags: string[];
public closed = false; public closed = false;
public closing = false; public closing = false;
public copy = undefined; public copy = undefined;
@ -46,6 +49,11 @@ export class SSHFileSystem implements vscode.FileSystemProvider {
this.logging = Logging.scope(`SSHFileSystem(${authority})`, false); this.logging = Logging.scope(`SSHFileSystem(${authority})`, false);
this.sftp.on('end', () => (this.closed = true, this.onCloseEmitter.fire())); this.sftp.on('end', () => (this.closed = true, this.onCloseEmitter.fire()));
this.logging.info('SSHFileSystem created'); 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() { public disconnect() {
this.closing = true; this.closing = true;
@ -162,11 +170,17 @@ export class SSHFileSystem implements vscode.FileSystemProvider {
e = vscode.FileSystemError.FileNotFound(uri); e = vscode.FileSystemError.FileNotFound(uri);
// Whenever a workspace opens, VSCode (and extensions) (indirectly) stat a bunch of files // 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, ...) // (.vscode/tasks.json etc, .git/, node_modules for NodeJS, pom.xml for Maven, ...)
const flags = `${ignore[0] ? 'F' : ''}${ignore[1] ? 'A' : ''}`; if (this.debugFlags.includes('ignoredmissing')) {
this.logging.debug(`Ignored (${flags}) 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; 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 // Convert SSH2Stream error codes into VS Code errors
if (doThrow && typeof e.code === 'number') { if (doThrow && typeof e.code === 'number') {
const oldE = e; const oldE = e;
@ -179,7 +193,8 @@ export class SSHFileSystem implements vscode.FileSystemProvider {
} else if (e.code === 7) { // Connection lost } else if (e.code === 7) { // Connection lost
e = vscode.FileSystemError.Unavailable(uri); 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 // Display an error notification if the FS_ERROR_NOTIFICATION flag is enabled
const [flagCH] = getFlagBoolean('FS_NOTIFY_ERRORS', true, this.config.flags); const [flagCH] = getFlagBoolean('FS_NOTIFY_ERRORS', true, this.config.flags);

Loading…
Cancel
Save