@@ -125,69 +125,77 @@ export class ConnectionManagementService {
125125
126126 public async connect ( connLabel : string ) : Promise < void > {
127127 /* c8 ignore start */
128- const connection = this . retrieveConnection ( connLabel ) ;
129- if ( ! connection ) {
130- return ;
131- }
132- if ( connection instanceof KdbNode ) {
133- const connectionString = this . retrieveLocalConnectionString ( connection ) ;
134- const authCredentials = connection . details . auth
135- ? await ext . secretSettings . getAuthData ( connection . children [ 0 ] )
136- : undefined ;
137- const localConnection = new LocalConnection (
138- connectionString ,
139- connLabel ,
140- retrieveConnLabelsNames ( connection ) ,
141- authCredentials ? authCredentials . split ( ":" ) : undefined ,
142- connection . details . tls ,
143- ) ;
144- await localConnection . connect ( ( err , conn ) => {
145- if ( err ) {
146- this . connectFailBehaviour ( connLabel ) ;
147- return ;
148- }
149- if ( conn ) {
128+ try {
129+ const connection = this . retrieveConnection ( connLabel ) ;
130+ if ( ! connection ) {
131+ this . connectFailBehaviour (
132+ connLabel ,
133+ new Error ( `Connection ${ connLabel } not found.` ) ,
134+ ) ;
135+ return ;
136+ }
137+ if ( connection instanceof KdbNode ) {
138+ const connectionString = this . retrieveLocalConnectionString ( connection ) ;
139+ const authCredentials = connection . details . auth
140+ ? await ext . secretSettings . getAuthData ( connection . children [ 0 ] )
141+ : undefined ;
142+ const localConnection = new LocalConnection (
143+ connectionString ,
144+ connLabel ,
145+ retrieveConnLabelsNames ( connection ) ,
146+ authCredentials ? authCredentials . split ( ":" ) : undefined ,
147+ connection . details . tls ,
148+ ) ;
149+ await localConnection . connect ( ( err , conn ) => {
150+ if ( err ) {
151+ this . connectFailBehaviour ( connLabel , err ) ;
152+ return ;
153+ }
154+ if ( conn ) {
155+ notify (
156+ `Connection established successfully to: ${ connLabel } ` ,
157+ MessageKind . DEBUG ,
158+ {
159+ logger,
160+ telemetry :
161+ "Connection.Connected" +
162+ this . getTelemetryConnectionType ( connLabel ) ,
163+ } ,
164+ ) ;
165+
166+ ext . connectedConnectionList . push ( localConnection ) ;
167+
168+ this . connectSuccessBehaviour ( connection ) ;
169+ }
170+ } ) ;
171+ } else {
172+ ext . context . secrets . delete ( connection . details . alias ) ;
173+ const insightsConn : InsightsConnection = new InsightsConnection (
174+ connLabel ,
175+ connection ,
176+ ) ;
177+ await insightsConn . connect ( ) ;
178+ if ( insightsConn . connected ) {
150179 notify (
151180 `Connection established successfully to: ${ connLabel } ` ,
152181 MessageKind . DEBUG ,
153182 {
154183 logger,
184+ params : { insightsVersion : insightsConn . insightsVersion } ,
155185 telemetry :
156186 "Connection.Connected" +
157187 this . getTelemetryConnectionType ( connLabel ) ,
158188 } ,
159189 ) ;
160-
161- ext . connectedConnectionList . push ( localConnection ) ;
162-
190+ ext . connectedConnectionList . push ( insightsConn ) ;
163191 this . connectSuccessBehaviour ( connection ) ;
192+ } else {
193+ this . connectFailBehaviour ( connLabel ) ;
164194 }
165- } ) ;
166- } else {
167- ext . context . secrets . delete ( connection . details . alias ) ;
168- const insightsConn : InsightsConnection = new InsightsConnection (
169- connLabel ,
170- connection ,
171- ) ;
172- await insightsConn . connect ( ) ;
173- if ( insightsConn . connected ) {
174- notify (
175- `Connection established successfully to: ${ connLabel } ` ,
176- MessageKind . DEBUG ,
177- {
178- logger,
179- params : { insightsVersion : insightsConn . insightsVersion } ,
180- telemetry :
181- "Connection.Connected" +
182- this . getTelemetryConnectionType ( connLabel ) ,
183- } ,
184- ) ;
185- ext . connectedConnectionList . push ( insightsConn ) ;
186- this . connectSuccessBehaviour ( connection ) ;
187- } else {
188- this . connectFailBehaviour ( connLabel ) ;
195+ refreshDataSourcesPanel ( ) ;
189196 }
190- refreshDataSourcesPanel ( ) ;
197+ } catch ( error ) {
198+ this . connectFailBehaviour ( connLabel , error ) ;
191199 }
192200 /* c8 ignore stop */
193201 }
@@ -292,9 +300,10 @@ export class ConnectionManagementService {
292300 ext . serverProvider . reload ( ) ;
293301 }
294302
295- public connectFailBehaviour ( connLabel : string ) : void {
296- notify ( `Connection failed to: ${ connLabel } ` , MessageKind . ERROR , {
303+ public connectFailBehaviour ( connLabel : string , error ?: unknown ) : void {
304+ notify ( `Connection to ${ connLabel } failed. ` , MessageKind . ERROR , {
297305 logger,
306+ params : error ,
298307 telemetry :
299308 "Connection.Failed" + this . getTelemetryConnectionType ( connLabel ) ,
300309 } ) ;
0 commit comments