Skip to content

Commit 93f4337

Browse files
authored
Fix error handling when HostName is not available (#12022)
* Fix error handling when the HostName isn't available.
1 parent 69338b8 commit 93f4337

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Extension/src/SSH/sshHosts.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import * as path from 'path';
1010
import {
1111
Configuration, ConfigurationDirective,
1212
ConfigurationEntry,
13-
HostConfigurationDirective, parse,
13+
Type as ConfigurationEntryType,
14+
HostConfigurationDirective,
1415
ResolvedConfiguration,
15-
Type as ConfigurationEntryType
16+
parse
1617
} from 'ssh-config';
1718
import { promisify } from 'util';
1819
import * as vscode from 'vscode';
@@ -57,8 +58,14 @@ function extractHostNames(parsedConfig: Configuration): { [host: string]: string
5758
const hostNames: { [host: string]: string } = Object.create(null);
5859

5960
extractHosts(parsedConfig).forEach(host => {
60-
const resolvedConfig: ResolvedConfiguration = parsedConfig.compute(host);
61-
if (resolvedConfig.HostName) {
61+
let resolvedConfig: ResolvedConfiguration | undefined;
62+
try {
63+
resolvedConfig = parsedConfig.compute(host);
64+
} catch (e) {
65+
getSshChannel().appendLine(localize("failed.to.find.user.info.for.SSH",
66+
"Failed to find user info for SSH. This could be caused by VS Code being installed using 'snap'. Please reinstall VS Code using the 'deb' package if you are planning to use SSH features."));
67+
}
68+
if (resolvedConfig?.HostName !== undefined) {
6269
hostNames[host] = resolvedConfig.HostName;
6370
} else {
6471
hostNames[host] = host;

0 commit comments

Comments
 (0)