File tree Expand file tree Collapse file tree 2 files changed +44
-14
lines changed
databricks-sdk-js/src/auth
databricks-vscode/src/configuration Expand file tree Collapse file tree 2 files changed +44
-14
lines changed Original file line number Diff line number Diff line change @@ -37,18 +37,23 @@ export async function loadConfigFile(filePath?: string): Promise<Profiles> {
3737 }
3838
3939 let config : any ;
40+ let profiles : Profiles = { } ;
4041 try {
4142 config = parse ( fileContents ) ;
42- } catch ( e ) {
43- throw new ConfigFileError ( `Can't parse ${ filePath } ` ) ;
44- }
45-
46- let profiles : Profiles = { } ;
47- for ( let profile in config ) {
48- profiles [ profile ] = {
49- host : new URL ( config [ profile ] . host ) ,
50- token : config [ profile ] . token ,
51- } ;
43+ for ( let profile in config ) {
44+ profiles [ profile ] = {
45+ host : new URL ( config [ profile ] . host ) ,
46+ token : config [ profile ] . token ,
47+ } ;
48+ }
49+ } catch ( e : unknown ) {
50+ let message ;
51+ if ( e instanceof Error ) {
52+ message = `${ e . name } : ${ e . message } ` ;
53+ } else {
54+ message = e ;
55+ }
56+ throw new ConfigFileError ( `Can't parse ${ filePath } : ${ message } ` ) ;
5257 }
5358
5459 return profiles ;
Original file line number Diff line number Diff line change 1- import { loadConfigFile , Profiles } from "@databricks/databricks-sdk" ;
1+ import {
2+ ConfigFileError ,
3+ loadConfigFile ,
4+ Profiles ,
5+ resolveConfigFilePath ,
6+ } from "@databricks/databricks-sdk" ;
7+ import { stat , unlink } from "fs/promises" ;
28import { QuickPickItem , QuickPickItemKind , window } from "vscode" ;
39import { CliWrapper } from "../cli/CliWrapper" ;
410import { MultiStepInput } from "../ui/wizard" ;
@@ -24,12 +30,31 @@ export async function selectProfile(
2430 const title = "Select Databricks Profile" ;
2531
2632 async function pickProfile ( input : MultiStepInput , state : Partial < State > ) {
27- let profiles : Profiles ;
33+ let profiles : Profiles = { } ;
2834 try {
2935 profiles = await loadConfigFile ( ) ;
3036 } catch ( e ) {
31- console . error ( e ) ;
32- throw e ;
37+ if ( ! ( e instanceof ConfigFileError ) ) {
38+ throw e ;
39+ }
40+ const path = resolveConfigFilePath ( ) ;
41+ let stats ;
42+ try {
43+ stats = await stat ( path ) ;
44+ } catch ( e ) {
45+ /*file doesn't exist*/
46+ }
47+ if ( stats ?. isFile ( ) ) {
48+ const option = await window . showErrorMessage (
49+ e . message ,
50+ "Overwrite" ,
51+ "Cancel"
52+ ) ;
53+ if ( option === "Cancel" ) {
54+ return ;
55+ }
56+ await unlink ( path ) ;
57+ }
3358 }
3459
3560 let items : Array < QuickPickItem > = Object . keys ( profiles ) . map (
You can’t perform that action at this time.
0 commit comments