Skip to content

Commit 5d02194

Browse files
committed
Throw errors if accessing paths before set
1 parent 5ea1d8b commit 5d02194

5 files changed

Lines changed: 47 additions & 19 deletions

File tree

packages/ide/src/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { field, logger, time, Time } from "@coder/logger";
2-
import { ISharedProcessData } from "@coder/protocol";
2+
import { SharedProcessData } from "@coder/protocol";
33
import { retry } from "./retry";
44
import { upload } from "./upload";
55
import { client } from "./fill/client";
@@ -25,7 +25,7 @@ export abstract class IdeClient {
2525
private readonly loadTime: Time;
2626

2727
public readonly initData = client.initData;
28-
public readonly sharedProcessData: Promise<ISharedProcessData>;
28+
public readonly sharedProcessData: Promise<SharedProcessData>;
2929
public readonly onSharedProcessActive = client.onSharedProcessActive;
3030

3131
public constructor() {

packages/protocol/src/browser/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ReadWriteConnection, InitData, OperatingSystem, ISharedProcessData } from "../common/connection";
1+
import { ReadWriteConnection, InitData, OperatingSystem, SharedProcessData } from "../common/connection";
22
import { NewEvalMessage, ServerMessage, EvalDoneMessage, EvalFailedMessage, TypedValue, ClientMessage, NewSessionMessage, TTYDimensions, SessionOutputMessage, CloseSessionInputMessage, WorkingInitMessage, EvalEventMessage } from "../proto";
33
import { Emitter } from "@coder/events";
44
import { logger, field } from "@coder/logger";
@@ -30,7 +30,7 @@ export class Client {
3030
private readonly initDataEmitter = new Emitter<InitData>();
3131
private readonly initDataPromise: Promise<InitData>;
3232

33-
private readonly sharedProcessActiveEmitter = new Emitter<ISharedProcessData>();
33+
private readonly sharedProcessActiveEmitter = new Emitter<SharedProcessData>();
3434
public readonly onSharedProcessActive = this.sharedProcessActiveEmitter.event;
3535

3636
/**

packages/protocol/src/common/connection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface InitData {
2424
readonly builtInExtensionsDirectory: string;
2525
}
2626

27-
export interface ISharedProcessData {
27+
export interface SharedProcessData {
2828
readonly socketPath: string;
2929
readonly logPath: string;
3030
}

packages/vscode/src/client.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,10 @@ export class Client extends IdeClient {
156156
protected initialize(): Promise<void> {
157157
registerContextMenuListener();
158158

159-
const pathSets = this.sharedProcessData.then((data) => {
160-
paths._paths.socketPath = data.socketPath;
161-
process.env.VSCODE_LOGS = data.logPath;
162-
});
163-
164159
this._clipboardContextKey = new RawContextKey("nativeClipboard", this.clipboard.isEnabled);
165160

166-
return this.task("Start workbench", 1000, async (data) => {
167-
paths._paths.appData = data.dataDirectory;
168-
paths._paths.defaultUserData = data.dataDirectory;
161+
return this.task("Start workbench", 1000, async (data, sharedData) => {
162+
paths._paths.initialize(data, sharedData);
169163
this._builtInExtensionsDirectory = data.builtInExtensionsDirectory;
170164
process.env.SHELL = data.shell;
171165

@@ -190,7 +184,7 @@ export class Client extends IdeClient {
190184
bounded.set(enabled);
191185
});
192186
this.clipboard.initialize();
193-
}, this.initData, pathSets);
187+
}, this.initData, this.sharedProcessData);
194188
}
195189
}
196190

packages/vscode/src/fill/paths.ts

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,42 @@
1-
export const _paths = {
2-
appData: "/tmp",
3-
defaultUserData: "/tmp",
4-
socketPath: "/tmp/vscode-remote.sock",
5-
};
1+
import { InitData, SharedProcessData } from "@coder/protocol";
62

3+
class Paths {
4+
private _appData: string | undefined;
5+
private _defaultUserData: string | undefined;
6+
private _socketPath: string | undefined;
7+
8+
public get appData(): string {
9+
if (typeof this._appData === "undefined") {
10+
throw new Error("trying to access appData before it has been set");
11+
}
12+
13+
return this._appData;
14+
}
15+
16+
public get defaultUserData(): string {
17+
if (typeof this._defaultUserData === "undefined") {
18+
throw new Error("trying to access defaultUserData before it has been set");
19+
}
20+
21+
return this._defaultUserData;
22+
}
23+
24+
public get socketPath(): string {
25+
if (typeof this._socketPath === "undefined") {
26+
throw new Error("trying to access socketPath before it has been set");
27+
}
28+
29+
return this._socketPath;
30+
}
31+
32+
public initialize(data: InitData, sharedData: SharedProcessData): void {
33+
process.env.VSCODE_LOGS = sharedData.logPath;
34+
this._appData = data.dataDirectory;
35+
this._defaultUserData = data.dataDirectory;
36+
this._socketPath = sharedData.socketPath;
37+
}
38+
}
39+
40+
export const _paths = new Paths();
741
export const getAppDataPath = (): string => _paths.appData;
842
export const getDefaultUserDataPath = (): string => _paths.defaultUserData;

0 commit comments

Comments
 (0)