Skip to content

Commit

Permalink
Better error handling and CHECK_HOME flag support for tryGetHome
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoofsKelvin committed Jul 6, 2021
1 parent 87d2cf8 commit bda36c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ function parseFlagList(list: string[] | undefined, origin: string): Record<strin
- Makes it that commands are joined together using ` && ` instead of `; `
CHECK_HOME (boolean) (default=true)
- Determines whether we check if the home directory exists during `createFileSystem` in the Manager
- If `tryGetHome` fails while creating the connection, throw an error if this flag is set, otherwise default to `/`
REMOTE_COMMANDS (boolean) (default=false)
- Enables automatically launching a background command terminal during connection setup
- Enables attempting to inject a file to be sourced by the remote shells (which adds the `code` alias)
Expand Down
16 changes: 13 additions & 3 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,21 @@ export class ConnectionManager {
// Start the actual SSH connection
const client = await createSSH(actualConfig);
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
const home = await tryGetHome(client);
let home = await tryGetHome(client);
if (!home) {
await vscode.window.showErrorMessage(`Couldn't detect the home directory for '${name}'`, 'Okay');
throw new Error(`Could not detect home directory`);
const [flagCH] = getFlagBoolean('CHECK_HOME', true, config.flags);
logging.error('Could not detect home directory');
if (flagCH) {
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 {
logging.warning('The CHECK_HOME flag is disabled, default to \'/\' and ignore the error');
home = '';
}
}
// Calculate the environment
const environment: EnvironmentVariable[] = mergeEnvironment([], config.environment);
Expand Down

0 comments on commit bda36c9

Please sign in to comment.