Skip to content

Commit 88cfab9

Browse files
committed
feat: pipe error from spawned process into message
1 parent a59da21 commit 88cfab9

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

packages/core/src/awsService/ec2/model.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
SshError,
2727
startSshAgent,
2828
startVscodeRemote,
29-
testSsmConnection,
29+
testSshConnection,
3030
} from '../../shared/extensions/ssh'
3131
import { getLogger } from '../../shared/logger/logger'
3232
import { CancellationError, Timeout } from '../../shared/utilities/timeoutUtils'
@@ -200,7 +200,7 @@ export class Ec2Connecter implements vscode.Disposable {
200200
const remoteEnv = await this.prepareEc2RemoteEnvWithProgress(selection, remoteUser)
201201
const testSession = await this.ssmClient.startSession(selection.instanceId, 'AWS-StartSSHSession')
202202
try {
203-
await testSsmConnection(
203+
await testSshConnection(
204204
remoteEnv.SessionProcess,
205205
remoteEnv.hostname,
206206
remoteEnv.sshPath,
@@ -215,7 +215,8 @@ export class Ec2Connecter implements vscode.Disposable {
215215
remoteUser.name
216216
)
217217
} catch (err) {
218-
const message = err instanceof SshError ? 'Testing SSH connection to instance failed' : ''
218+
const message =
219+
err instanceof SshError ? `Testing SSM connection to instance failed with error: ${err.message}` : ''
219220
this.throwConnectionError(message, selection, { ...(err as Error), code: 'EC2SSMTestConnect' })
220221
} finally {
221222
await this.ssmClient.terminateSession(testSession)

packages/core/src/shared/extensions/ssh.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class RemoteSshSettings extends Settings.define('remote.SSH', remoteSshTy
130130
}
131131
}
132132

133-
export async function testSsmConnection(
133+
export async function testSshConnection(
134134
ProcessClass: typeof ChildProcess,
135135
hostname: string,
136136
sshPath: string,
@@ -146,7 +146,8 @@ export async function testSsmConnection(
146146
},
147147
})
148148
} catch (error) {
149-
throw new SshError('SSH connection test failed', { cause: error as Error })
149+
const errorMessage = [process.result()?.stderr ?? ''].join('\n')
150+
throw new SshError(errorMessage, { cause: error as Error })
150151
}
151152
}
152153

packages/core/src/test/shared/extensions/ssh.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
import * as assert from 'assert'
66
import { ChildProcess } from '../../../shared/utilities/processUtils'
7-
import { startSshAgent, testSsmConnection } from '../../../shared/extensions/ssh'
7+
import { startSshAgent, testSshConnection } from '../../../shared/extensions/ssh'
88
import { createBoundProcess } from '../../../shared/remoteSession'
99
import { createExecutableFile, createTestWorkspaceFolder } from '../../testUtil'
1010
import { WorkspaceFolder } from 'vscode'
@@ -74,7 +74,7 @@ describe('testSshConnection', function () {
7474
} as SSM.StartSessionResponse
7575

7676
await createExecutableFile(sshPath, echoEnvVarsCmd(['MY_VAR']))
77-
const r = await testSsmConnection(process, 'localhost', sshPath, 'test-user', session)
77+
const r = await testSshConnection(process, 'localhost', sshPath, 'test-user', session)
7878
assertOutputContains(r.stdout, 'yes')
7979
})
8080

@@ -97,15 +97,15 @@ describe('testSshConnection', function () {
9797
const process = createBoundProcess(envProvider)
9898

9999
await createExecutableFile(sshPath, echoEnvVarsCmd(['SESSION_ID', 'STREAM_URL', 'TOKEN']))
100-
const r = await testSsmConnection(process, 'localhost', sshPath, 'test-user', newSession)
100+
const r = await testSshConnection(process, 'localhost', sshPath, 'test-user', newSession)
101101
assertOutputContains(r.stdout, `${newSession.SessionId} ${newSession.StreamUrl} ${newSession.TokenValue}`)
102102
})
103103

104104
it('passes proper args to the ssh invoke', async function () {
105105
const executableFileContent = isWin() ? `echo "%1 %2"` : `echo "$1 $2"`
106106
const process = createBoundProcess(async () => ({}))
107107
await createExecutableFile(sshPath, executableFileContent)
108-
const r = await testSsmConnection(process, 'localhost', sshPath, 'test-user', {} as SSM.StartSessionResponse)
108+
const r = await testSshConnection(process, 'localhost', sshPath, 'test-user', {} as SSM.StartSessionResponse)
109109
assertOutputContains(r.stdout, '-T')
110110
assertOutputContains(r.stdout, 'test-user@localhost')
111111
})

0 commit comments

Comments
 (0)