Skip to content

Commit

Permalink
Improve effect of CHECK_HOME flag (fixes #277)
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoofsKelvin committed Jul 31, 2021
1 parent ef40b07 commit c7f1261
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Client, ClientChannel, SFTPWrapper } from 'ssh2';
import * as vscode from 'vscode';
import { configMatches, getFlagBoolean, loadConfigs } from './config';
import type { EnvironmentVariable, FileSystemConfig } from './fileSystemConfig';
import { Logging } from './logging';
import { Logging, LOGGING_NO_STACKTRACE } from './logging';
import type { SSHPseudoTerminal } from './pseudoTerminal';
import type { SSHFileSystem } from './sshFileSystem';
import { mergeEnvironment, toPromise } from './utils';
Expand Down Expand Up @@ -137,16 +137,18 @@ export class ConnectionManager {
if (!client) throw new Error(`Could not create SSH session for '${name}'`);
logging.info(`Remote version: ${(client as any)._remoteVer || 'N/A'}`);
// Query home directory
let home = await tryGetHome(client);
if (!home) {
let home = await tryGetHome(client).catch((e: Error) => e);
if (typeof home !== 'string') {
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 (home) logging.error(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');
await vscode.window.showErrorMessage(`Couldn't detect the home directory for '${name}'`, 'Okay');
throw new Error(`Could not detect home directory`);
} else {
if (home) logging.warning(home);
logging.warning('The CHECK_HOME flag is disabled, default to \'/\' and ignore the error');
home = '';
}
Expand Down
2 changes: 1 addition & 1 deletion src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class Logger {
public info(message: string, options: Partial<LoggingOptions> = {}) {
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);
}
public error(message: string | Error, options: Partial<LoggingOptions> = {}) {
Expand Down

0 comments on commit c7f1261

Please sign in to comment.