Skip to content

Commit e479735

Browse files
[DECO-150] Show proper error message if no sync destination when running file (#141)
https://user-images.githubusercontent.com/88345179/198275420-0636faf4-583b-4901-9608-c3d12f3bed7b.mov
1 parent 1b7f0e6 commit e479735

File tree

5 files changed

+74
-15
lines changed

5 files changed

+74
-15
lines changed

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Cluster, Repo} from "@databricks/databricks-sdk";
22
import {homedir} from "node:os";
3+
import {resolve} from "node:path";
34
import {
45
Disposable,
56
QuickPickItem,
@@ -184,18 +185,24 @@ export class ConnectionCommands implements Disposable {
184185
}));
185186
quickPick.busy = false;
186187

187-
quickPick.onDidAccept(async () => {
188-
const repoPath = quickPick.selectedItems[0].path;
189-
await this.connectionManager.attachSyncDestination(
190-
Uri.from({
191-
scheme: "dbws",
192-
path: repoPath,
193-
})
194-
);
195-
quickPick.dispose();
196-
});
188+
await new Promise<void>((resolve) => {
189+
quickPick.onDidAccept(async () => {
190+
const repoPath = quickPick.selectedItems[0].path;
191+
await this.connectionManager.attachSyncDestination(
192+
Uri.from({
193+
scheme: "dbws",
194+
path: repoPath,
195+
})
196+
);
197+
quickPick.dispose();
198+
resolve();
199+
});
197200

198-
quickPick.onDidHide(() => quickPick.dispose());
201+
quickPick.onDidHide(() => {
202+
quickPick.dispose();
203+
resolve();
204+
});
205+
});
199206
};
200207
}
201208

packages/databricks-vscode/src/run/DabaricksRuntime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414

1515
import {SyncDestination} from "../configuration/SyncDestination";
1616
import {ConnectionManager} from "../configuration/ConnectionManager";
17-
import {promptForClusterStart} from "../ui/prompts";
17+
import {promptForClusterStart} from "./prompts";
1818
import {CodeSynchronizer} from "../sync/CodeSynchronizer";
1919

2020
export interface OutputEvent {

packages/databricks-vscode/src/run/DabaricksWorkflowDebugAdapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {DebugProtocol} from "@vscode/debugprotocol";
2424
import {ConnectionManager} from "../configuration/ConnectionManager";
2525
import {Subject} from "./Subject";
2626
import {runAsWorkflow} from "./WorkflowOutputPanel";
27-
import {promptForClusterStart} from "../ui/prompts";
27+
import {promptForClusterStart} from "./prompts";
2828
import {CodeSynchronizer} from "../sync/CodeSynchronizer";
2929

3030
/**

packages/databricks-vscode/src/run/RunCommands.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import {resolve} from "path";
12
import {commands, debug, Uri, window} from "vscode";
23
import {ConnectionManager} from "../configuration/ConnectionManager";
4+
import {promptForAttachingSyncDest} from "./prompts";
35
import {isNotebook} from "../utils";
46

57
/**
@@ -26,6 +28,20 @@ export class RunCommands {
2628
await this.connection.waitForConnect();
2729
}
2830

31+
if (this.connection.syncDestination === undefined) {
32+
await promptForAttachingSyncDest(async () => {
33+
window.showErrorMessage(
34+
"Execution cancelled because no Databricks Repo is attached"
35+
);
36+
});
37+
if (this.connection.syncDestination === undefined) {
38+
window.showErrorMessage(
39+
"Execution cancelled because no Databricks Repo is attached"
40+
);
41+
return;
42+
}
43+
}
44+
2945
await commands.executeCommand("databricks.sync.start");
3046
await debug.startDebugging(
3147
undefined,
@@ -52,6 +68,20 @@ export class RunCommands {
5268
await this.connection.waitForConnect();
5369
}
5470

71+
if (this.connection.syncDestination === undefined) {
72+
await promptForAttachingSyncDest(async () => {
73+
window.showErrorMessage(
74+
"Execution cancelled because no Databricks Repo is attached"
75+
);
76+
});
77+
if (this.connection.syncDestination === undefined) {
78+
window.showErrorMessage(
79+
"Execution cancelled because no Databricks Repo is attached"
80+
);
81+
return;
82+
}
83+
}
84+
5585
await commands.executeCommand("databricks.sync.start");
5686
await debug.startDebugging(
5787
undefined,

packages/databricks-vscode/src/ui/prompts.ts renamed to packages/databricks-vscode/src/run/prompts.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,39 @@ export async function promptForClusterStart(
1010
const response = await window.showErrorMessage(
1111
"The attached cluster is not running.",
1212
"Start Cluster",
13-
"Cancel Execution"
13+
"Cancel"
1414
);
1515
switch (response) {
1616
case "Start Cluster":
1717
await onAccept();
1818
await commands.executeCommand("databricks.cluster.start");
1919
return true;
20-
case "Cancel Execution":
20+
case "Cancel":
2121
await onReject();
2222
return false;
2323
}
2424
}
2525
return true;
2626
}
27+
28+
export async function promptForAttachingSyncDest(
29+
onReject: () => Promise<void>,
30+
onAccept: () => Promise<void> = async () => {}
31+
) {
32+
const response = await window.showErrorMessage(
33+
"Please configure a Databricks Repo for syncing",
34+
"Attach Repo",
35+
"Cancel"
36+
);
37+
switch (response) {
38+
case "Attach Repo":
39+
await commands.executeCommand(
40+
"databricks.connection.attachSyncDestination"
41+
);
42+
await onAccept();
43+
return true;
44+
case "Cancel":
45+
await onReject();
46+
return false;
47+
}
48+
}

0 commit comments

Comments
 (0)