@@ -23,6 +23,7 @@ import { DefaultIamClient } from '../../shared/clients/iamClient'
2323import { ErrorInformation } from '../../shared/errors'
2424import {
2525 sshAgentSocketVariable ,
26+ SSHError ,
2627 startSshAgent ,
2728 startVscodeRemote ,
2829 testSshConnection ,
@@ -154,13 +155,6 @@ export class Ec2Connecter implements vscode.Disposable {
154155 }
155156 }
156157
157- public throwGeneralConnectionError ( selection : Ec2Selection , error : Error ) {
158- this . throwConnectionError ( 'Unable to connect to target instance. ' , selection , {
159- code : 'EC2SSMConnect' ,
160- cause : error ,
161- } )
162- }
163-
164158 public async checkForStartSessionError ( selection : Ec2Selection ) : Promise < void > {
165159 await this . checkForInstanceStatusError ( selection )
166160
@@ -189,7 +183,7 @@ export class Ec2Connecter implements vscode.Disposable {
189183 const response = await this . ssmClient . startSession ( selection . instanceId )
190184 await this . openSessionInTerminal ( response , selection )
191185 } catch ( err : unknown ) {
192- this . throwGeneralConnectionError ( selection , err as Error )
186+ this . throwConnectionError ( '' , selection , err as Error )
193187 }
194188 }
195189
@@ -209,7 +203,8 @@ export class Ec2Connecter implements vscode.Disposable {
209203 )
210204 await startVscodeRemote ( remoteEnv . SessionProcess , remoteEnv . hostname , '/' , remoteEnv . vscPath , remoteUser )
211205 } catch ( err ) {
212- this . throwGeneralConnectionError ( selection , err as Error )
206+ const message = err instanceof SSHError ? 'Testing SSH connection to instance failed' : ''
207+ this . throwConnectionError ( message , selection , err as Error )
213208 } finally {
214209 await this . ssmClient . terminateSession ( testSession )
215210 }
0 commit comments