@@ -21,6 +21,7 @@ import {selectProfile} from "./selectProfileWizard";
2121import { ClusterManager } from "../cluster/ClusterManager" ;
2222import { workspace } from "@databricks/databricks-sdk" ;
2323import { DatabricksWorkspace } from "./DatabricksWorkspace" ;
24+ import { NamedLogger } from "@databricks/databricks-sdk/dist/logging" ;
2425
2526const extensionVersion = require ( "../../package.json" ) . version ;
2627
@@ -94,6 +95,18 @@ export class ConnectionManager {
9495 }
9596
9697 async login ( interactive : boolean = false ) : Promise < void > {
98+ try {
99+ await this . _login ( interactive ) ;
100+ } catch ( e ) {
101+ NamedLogger . getOrCreate ( "Extension" ) . error ( "Login Error" , e ) ;
102+ if ( interactive ) {
103+ window . showErrorMessage ( `Login error ${ JSON . stringify ( e ) } ` ) ;
104+ }
105+ this . updateState ( "DISCONNECTED" ) ;
106+ await this . logout ( ) ;
107+ }
108+ }
109+ private async _login ( interactive : boolean = false ) : Promise < void > {
97110 await this . logout ( ) ;
98111 this . updateState ( "CONNECTING" ) ;
99112
@@ -124,7 +137,7 @@ export class ConnectionManager {
124137 ) ;
125138 } catch ( e : any ) {
126139 const message = `Can't login to Databricks: ${ e . message } ` ;
127- console . error ( message ) ;
140+ NamedLogger . getOrCreate ( "Extension" ) . error ( message , e ) ;
128141 if ( interactive ) {
129142 window . showErrorMessage ( message ) ;
130143 }
@@ -146,7 +159,7 @@ export class ConnectionManager {
146159 message =
147160 "Files in Repos is not enabled for this workspace. Please enable it in the Databricks UI." ;
148161 }
149- console . error ( message ) ;
162+ NamedLogger . getOrCreate ( "Extension" ) . error ( message ) ;
150163 if ( interactive ) {
151164 let result = await window . showWarningMessage (
152165 message ,
@@ -230,7 +243,11 @@ export class ConnectionManager {
230243 profile
231244 ) ;
232245 } catch ( e : any ) {
233- console . error ( e ) ;
246+ NamedLogger . getOrCreate ( "Extension" ) . error (
247+ `Connection with profile "${ profile } " failed` ,
248+ e
249+ ) ;
250+
234251 const response = await window . showWarningMessage (
235252 `Connection with profile "${ profile } " failed with error: "${ e . message } "."` ,
236253 "Retry" ,
@@ -277,24 +294,40 @@ export class ConnectionManager {
277294 cluster : Cluster | string ,
278295 skipWrite = false
279296 ) : Promise < void > {
280- if ( this . cluster === cluster ) {
281- return ;
282- }
297+ try {
298+ if ( this . cluster === cluster ) {
299+ return ;
300+ }
283301
284- if ( typeof cluster === "string" ) {
285- cluster = await Cluster . fromClusterId ( this . _apiClient ! , cluster ) ;
286- }
302+ if ( typeof cluster === "string" ) {
303+ cluster = await Cluster . fromClusterId (
304+ this . _apiClient ! ,
305+ cluster
306+ ) ;
307+ }
287308
288- if ( ! skipWrite ) {
289- this . _projectConfigFile ! . clusterId = cluster . id ;
290- await this . _projectConfigFile ! . write ( ) ;
291- }
309+ if ( ! skipWrite ) {
310+ this . _projectConfigFile ! . clusterId = cluster . id ;
311+ await this . _projectConfigFile ! . write ( ) ;
312+ }
292313
293- this . updateCluster ( cluster ) ;
314+ this . updateCluster ( cluster ) ;
315+ } catch ( e ) {
316+ NamedLogger . getOrCreate ( "Extension" ) . error (
317+ "Attach Cluster error" ,
318+ e
319+ ) ;
320+ window . showErrorMessage (
321+ `Error in attaching cluster destination ${
322+ typeof cluster === "string" ? cluster : cluster . id
323+ } `
324+ ) ;
325+ await this . detachCluster ( ) ;
326+ }
294327 }
295328
296329 async detachCluster ( ) : Promise < void > {
297- if ( ! this . cluster ) {
330+ if ( ! this . cluster && this . _projectConfigFile ?. clusterId === undefined ) {
298331 return ;
299332 }
300333
@@ -310,32 +343,46 @@ export class ConnectionManager {
310343 workspacePath : Uri ,
311344 skipWrite = false
312345 ) : Promise < void > {
313- if (
314- ! vscodeWorkspace . workspaceFolders ||
315- ! vscodeWorkspace . workspaceFolders . length
316- ) {
317- // TODO how do we handle this?
318- return ;
319- }
346+ try {
347+ if (
348+ ! vscodeWorkspace . workspaceFolders ||
349+ ! vscodeWorkspace . workspaceFolders . length
350+ ) {
351+ // TODO how do we handle this?
352+ return ;
353+ }
320354
321- if ( ! skipWrite ) {
322- this . _projectConfigFile ! . workspacePath = workspacePath . path ;
323- await this . _projectConfigFile ! . write ( ) ;
324- }
355+ if ( ! skipWrite ) {
356+ this . _projectConfigFile ! . workspacePath = workspacePath . path ;
357+ await this . _projectConfigFile ! . write ( ) ;
358+ }
325359
326- const wsUri = vscodeWorkspace . workspaceFolders [ 0 ] . uri ;
327- if ( this . apiClient === undefined ) {
328- throw new Error (
329- "Can't attach a Repo when profile is not connected"
360+ const wsUri = vscodeWorkspace . workspaceFolders [ 0 ] . uri ;
361+ if ( this . apiClient === undefined ) {
362+ throw new Error (
363+ "Can't attach a Repo when profile is not connected"
364+ ) ;
365+ }
366+ this . updateSyncDestination (
367+ await SyncDestination . from ( this . apiClient , workspacePath , wsUri )
368+ ) ;
369+ } catch ( e ) {
370+ NamedLogger . getOrCreate ( "Extension" ) . error (
371+ "Attach Sync Destination error" ,
372+ e
373+ ) ;
374+ window . showErrorMessage (
375+ `Error in attaching sync destination ${ workspacePath . fsPath } `
330376 ) ;
377+ await this . detachSyncDestination ( ) ;
331378 }
332- this . updateSyncDestination (
333- await SyncDestination . from ( this . apiClient , workspacePath , wsUri )
334- ) ;
335379 }
336380
337381 async detachSyncDestination ( ) : Promise < void > {
338- if ( ! this . _syncDestination ) {
382+ if (
383+ ! this . _syncDestination &&
384+ this . _projectConfigFile ?. workspacePath === undefined
385+ ) {
339386 return ;
340387 }
341388
0 commit comments