Skip to content

Commit bb39878

Browse files
Fix creation of .ide if it doesn't exists (#585)
1 parent 1fd0090 commit bb39878

File tree

5 files changed

+59
-29
lines changed

5 files changed

+59
-29
lines changed

packages/databricks-sdk-js/src/services/wsfs/WorkspaceFsDir.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {posix} from "path";
2-
import {ApiClientResponseError} from "../../api-client";
32
import {Context, context} from "../../context";
43
import {WorkspaceFsEntity} from ".";
54
import {ExposedLoggers, withLogContext} from "../../logging";
@@ -45,8 +44,8 @@ export class WorkspaceFsDir extends WorkspaceFsEntity {
4544
await this._workspaceFsService.mkdirs({path: validPath});
4645
} catch (e: unknown) {
4746
let err: any = e;
48-
if (e instanceof ApiClientResponseError) {
49-
if (e.error_code === "RESOURCE_ALREADY_EXISTS") {
47+
if (e instanceof Error) {
48+
if (e.message.includes("RESOURCE_ALREADY_EXISTS")) {
5049
err = new Error(
5150
`Can't create ${path} as child of ${this.path}: A file with same path exists`
5251
);

packages/databricks-sdk-js/src/services/wsfs/WorkspaceFsEntity.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ export abstract class WorkspaceFsEntity {
155155
return entity;
156156
} catch (e) {
157157
if (
158-
e instanceof ApiClientResponseError &&
159-
e.error_code === "RESOURCE_DOES_NOT_EXIST"
158+
e instanceof Error &&
159+
e.message.includes("RESOURCE_DOES_NOT_EXIST")
160160
) {
161161
return undefined;
162162
}

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

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
Cluster,
3-
WorkspaceFsEntity,
4-
WorkspaceFsUtils,
5-
} from "@databricks/databricks-sdk";
1+
import {Cluster, WorkspaceFsEntity} from "@databricks/databricks-sdk";
62
import {homedir} from "node:os";
73
import {
84
Disposable,
@@ -217,25 +213,10 @@ export class ConnectionCommands implements Disposable {
217213
return;
218214
}
219215

220-
let rootDir = await WorkspaceFsEntity.fromPath(
216+
const rootDir = await WorkspaceFsEntity.fromPath(
221217
wsClient,
222218
rootDirPath.path
223219
);
224-
if (!rootDir && workspaceConfigs.enableFilesInWorkspace) {
225-
const meDir = await WorkspaceFsEntity.fromPath(
226-
wsClient,
227-
`/Users/${me}`
228-
);
229-
if (WorkspaceFsUtils.isDirectory(meDir)) {
230-
rootDir = await meDir.mkdir(rootDirPath.path);
231-
}
232-
if (!rootDir) {
233-
window.showErrorMessage(
234-
`Can't find or create ${rootDirPath}`
235-
);
236-
return;
237-
}
238-
}
239220

240221
type WorkspaceFsQuickPickItem = QuickPickItem & {
241222
path?: string;

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import {WorkspaceClient, Cluster} from "@databricks/databricks-sdk";
1+
import {
2+
WorkspaceClient,
3+
Cluster,
4+
WorkspaceFsEntity,
5+
WorkspaceFsUtils,
6+
} from "@databricks/databricks-sdk";
27
import {
38
env,
49
EventEmitter,
@@ -202,9 +207,46 @@ export class ConnectionManager {
202207
this.updateSyncDestination(undefined);
203208
}
204209

210+
if (
211+
this.databricksWorkspace &&
212+
workspaceConfigs.enableFilesInWorkspace
213+
) {
214+
await this.createRootDirectory(
215+
workspaceClient,
216+
this.databricksWorkspace.currentFsRoot,
217+
this.databricksWorkspace.userName
218+
);
219+
}
220+
205221
this.updateState("CONNECTED");
206222
}
207223

224+
async createRootDirectory(
225+
wsClient: WorkspaceClient,
226+
rootDirPath: RemoteUri,
227+
me: string
228+
) {
229+
let rootDir = await WorkspaceFsEntity.fromPath(
230+
wsClient,
231+
rootDirPath.path
232+
);
233+
if (!rootDir) {
234+
const meDir = await WorkspaceFsEntity.fromPath(
235+
wsClient,
236+
`/Users/${me}`
237+
);
238+
if (WorkspaceFsUtils.isDirectory(meDir)) {
239+
rootDir = await meDir.mkdir(rootDirPath.path);
240+
}
241+
if (!rootDir) {
242+
window.showErrorMessage(
243+
`Can't find or create ${rootDirPath.path}`
244+
);
245+
return;
246+
}
247+
}
248+
}
249+
208250
async logout() {
209251
if (this._state === "DISCONNECTED") {
210252
return;

packages/databricks-vscode/src/workspace-fs/WorkspaceFsWorkflowWrapper.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ describe(__filename, async () => {
124124
anything()
125125
)
126126
).thenThrow(
127-
new ApiClientResponseError("", {}, "RESOURCE_DOES_NOT_EXIST")
127+
new ApiClientResponseError(
128+
"RESOURCE_DOES_NOT_EXIST",
129+
{},
130+
"RESOURCE_DOES_NOT_EXIST"
131+
)
128132
);
129133

130134
when(
@@ -202,7 +206,11 @@ describe(__filename, async () => {
202206
anything()
203207
)
204208
).thenThrow(
205-
new ApiClientResponseError("", {}, "RESOURCE_DOES_NOT_EXIST")
209+
new ApiClientResponseError(
210+
"RESOURCE_DOES_NOT_EXIST",
211+
{},
212+
"RESOURCE_DOES_NOT_EXIST"
213+
)
206214
);
207215

208216
when(

0 commit comments

Comments
 (0)