Skip to content

Commit 6b5f50c

Browse files
committed
Handle shared process error event; add some logging
1 parent 6708c8a commit 6b5f50c

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

packages/server/src/vscode/sharedProcess.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { StdioIpcHandler } from "../ipc";
77
import { ParsedArgs } from "vs/platform/environment/common/environment";
88
import { Emitter } from "@coder/events/src";
99
import { retry } from "@coder/ide/src/retry";
10-
import { logger, Level } from "@coder/logger";
10+
import { logger, field, Level } from "@coder/logger";
1111

1212
export enum SharedProcessState {
1313
Stopped,
@@ -30,6 +30,7 @@ export class SharedProcess {
3030
private readonly onStateEmitter = new Emitter<SharedProcessEvent>();
3131
public readonly onState = this.onStateEmitter.event;
3232
private readonly retryName = "Shared process";
33+
private readonly logger = logger.named("shared");
3334

3435
public constructor(
3536
private readonly userDataDir: string,
@@ -65,12 +66,34 @@ export class SharedProcess {
6566
state: SharedProcessState.Starting,
6667
});
6768
let resolved: boolean = false;
69+
const maybeStop = (error: string): void => {
70+
if (resolved) {
71+
return;
72+
}
73+
this.setState({
74+
error,
75+
state: SharedProcessState.Stopped,
76+
});
77+
if (!this.activeProcess) {
78+
return;
79+
}
80+
this.activeProcess.kill();
81+
};
6882
this.activeProcess = forkModule("vs/code/electron-browser/sharedProcess/sharedProcessMain", [], {
6983
env: {
7084
VSCODE_ALLOW_IO: "true",
7185
VSCODE_LOGS: process.env.VSCODE_LOGS,
7286
},
7387
});
88+
if (this.logger.level <= Level.Trace) {
89+
this.activeProcess.stdout.on("data", (data) => {
90+
this.logger.trace(() => ["stdout", field("data", data.toString())]);
91+
});
92+
}
93+
this.activeProcess.on("error", (error) => {
94+
this.logger.error("error", field("error", error));
95+
maybeStop(error.message);
96+
});
7497
this.activeProcess.on("exit", (err) => {
7598
if (this._state !== SharedProcessState.Stopped) {
7699
this.setState({
@@ -92,7 +115,7 @@ export class SharedProcess {
92115
"user-data-dir": this.userDataDir,
93116
"extensions-dir": extensionsDir,
94117
},
95-
logLevel: logger.level,
118+
logLevel: this.logger.level,
96119
sharedIPCHandle: this.socketPath,
97120
};
98121
this.ipcHandler!.send("handshake:hey there", "", data);
@@ -105,16 +128,8 @@ export class SharedProcess {
105128
});
106129
});
107130
this.activeProcess.stderr.on("data", (data) => {
108-
if (!resolved) {
109-
this.setState({
110-
error: data.toString(),
111-
state: SharedProcessState.Stopped,
112-
});
113-
if (!this.activeProcess) {
114-
return;
115-
}
116-
this.activeProcess.kill();
117-
}
131+
this.logger.error("stderr", field("data", data.toString()));
132+
maybeStop(data.toString());
118133
});
119134
}
120135

0 commit comments

Comments
 (0)