Improve effect of CHECK_HOME flag (fixes #277)

pull/285/head
Kelvin Schoofs 3 years ago
parent ef40b07b2d
commit c7f1261311

@ -4,7 +4,7 @@ import type { Client, ClientChannel, SFTPWrapper } from 'ssh2';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { configMatches, getFlagBoolean, loadConfigs } from './config'; import { configMatches, getFlagBoolean, loadConfigs } from './config';
import type { EnvironmentVariable, FileSystemConfig } from './fileSystemConfig'; import type { EnvironmentVariable, FileSystemConfig } from './fileSystemConfig';
import { Logging } from './logging'; import { Logging, LOGGING_NO_STACKTRACE } from './logging';
import type { SSHPseudoTerminal } from './pseudoTerminal'; import type { SSHPseudoTerminal } from './pseudoTerminal';
import type { SSHFileSystem } from './sshFileSystem'; import type { SSHFileSystem } from './sshFileSystem';
import { mergeEnvironment, toPromise } from './utils'; import { mergeEnvironment, toPromise } from './utils';
@ -137,16 +137,18 @@ export class ConnectionManager {
if (!client) throw new Error(`Could not create SSH session for '${name}'`); if (!client) throw new Error(`Could not create SSH session for '${name}'`);
logging.info(`Remote version: ${(client as any)._remoteVer || 'N/A'}`); logging.info(`Remote version: ${(client as any)._remoteVer || 'N/A'}`);
// Query home directory // Query home directory
let home = await tryGetHome(client); let home = await tryGetHome(client).catch((e: Error) => e);
if (!home) { if (typeof home !== 'string') {
const [flagCH] = getFlagBoolean('CHECK_HOME', true, config.flags); const [flagCH] = getFlagBoolean('CHECK_HOME', true, config.flags);
logging.error('Could not detect home directory'); logging.error('Could not detect home directory', LOGGING_NO_STACKTRACE);
if (flagCH) { if (flagCH) {
if (home) logging.error(home);
logging.info('If this is expected, disable the CHECK_HOME flag with \'-CHECK_HOME\':'); logging.info('If this is expected, disable the CHECK_HOME flag with \'-CHECK_HOME\':');
logging.info('https://github.com/SchoofsKelvin/vscode-sshfs/issues/270'); logging.info('https://github.com/SchoofsKelvin/vscode-sshfs/issues/270');
await vscode.window.showErrorMessage(`Couldn't detect the home directory for '${name}'`, 'Okay'); await vscode.window.showErrorMessage(`Couldn't detect the home directory for '${name}'`, 'Okay');
throw new Error(`Could not detect home directory`); throw new Error(`Could not detect home directory`);
} else { } else {
if (home) logging.warning(home);
logging.warning('The CHECK_HOME flag is disabled, default to \'/\' and ignore the error'); logging.warning('The CHECK_HOME flag is disabled, default to \'/\' and ignore the error');
home = ''; home = '';
} }

@ -130,7 +130,7 @@ class Logger {
public info(message: string, options: Partial<LoggingOptions> = {}) { public info(message: string, options: Partial<LoggingOptions> = {}) {
this.print('INFO', message, options); this.print('INFO', message, options);
} }
public warning(message: string, options: Partial<LoggingOptions> = {}) { public warning(message: string | Error, options: Partial<LoggingOptions> = {}) {
this.print('WARNING', message, options); this.print('WARNING', message, options);
} }
public error(message: string | Error, options: Partial<LoggingOptions> = {}) { public error(message: string | Error, options: Partial<LoggingOptions> = {}) {

Loading…
Cancel
Save