Skip to content

Commit 95ab5c6

Browse files
authored
Improve profiles loading (#1398)
## Changes Currently we show error notification during login process if cfg file doesn't exist. ## Tests Manually and existing tests
1 parent afe75eb commit 95ab5c6

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

packages/databricks-vscode/src/configuration/LoginWizard.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,15 @@ import {
2121
ProfileAuthProvider,
2222
} from "./auth/AuthProvider";
2323
import {FileUtils, UrlUtils} from "../utils";
24-
import {
25-
loadConfigFile,
26-
AuthType as SdkAuthType,
27-
} from "@databricks/databricks-sdk";
24+
import {AuthType as SdkAuthType} from "@databricks/databricks-sdk";
2825
import {randomUUID} from "crypto";
2926
import ini from "ini";
3027
import {appendFile, copyFile} from "fs/promises";
3128
import path from "path";
3229
import os from "os";
3330
import {createFile} from "fs-extra";
3431
import {getDatabricksConfigFilePath} from "../utils/fileUtils";
32+
import {stat} from "node:fs/promises";
3533

3634
interface AuthTypeQuickPickItem extends QuickPickItem {
3735
authType?: SdkAuthType;
@@ -388,7 +386,7 @@ export async function saveNewProfile(
388386
const configFilePath: string = getDatabricksConfigFilePath().fsPath;
389387
let shouldBackup = true;
390388
try {
391-
await loadConfigFile(configFilePath);
389+
await stat(configFilePath);
392390
} catch (e) {
393391
shouldBackup = false;
394392
await createFile(configFilePath);
@@ -450,19 +448,21 @@ export async function listProfiles(cliWrapper: CliWrapper) {
450448
title: "Loading Databricks profiles",
451449
},
452450
async () => {
453-
const profiles = (
454-
await cliWrapper.listProfiles(
455-
FileUtils.getDatabricksConfigFilePath().fsPath
456-
)
457-
).filter((profile) => {
451+
const cfgPath = FileUtils.getDatabricksConfigFilePath().fsPath;
452+
try {
453+
await stat(cfgPath);
454+
} catch (e) {
455+
return [];
456+
}
457+
const allProfiles = await cliWrapper.listProfiles(cfgPath);
458+
const profiles = allProfiles.filter((profile) => {
458459
try {
459460
UrlUtils.normalizeHost(profile.host!.toString());
460461
return true;
461462
} catch (e) {
462463
return false;
463464
}
464465
});
465-
466466
return profiles;
467467
}
468468
);

0 commit comments

Comments
 (0)