Handle shared process error
event; add some logging
This commit is contained in:
parent
6708c8a5c8
commit
6b5f50cddf
@ -7,7 +7,7 @@ import { StdioIpcHandler } from "../ipc";
|
|||||||
import { ParsedArgs } from "vs/platform/environment/common/environment";
|
import { ParsedArgs } from "vs/platform/environment/common/environment";
|
||||||
import { Emitter } from "@coder/events/src";
|
import { Emitter } from "@coder/events/src";
|
||||||
import { retry } from "@coder/ide/src/retry";
|
import { retry } from "@coder/ide/src/retry";
|
||||||
import { logger, Level } from "@coder/logger";
|
import { logger, field, Level } from "@coder/logger";
|
||||||
|
|
||||||
export enum SharedProcessState {
|
export enum SharedProcessState {
|
||||||
Stopped,
|
Stopped,
|
||||||
@ -30,6 +30,7 @@ export class SharedProcess {
|
|||||||
private readonly onStateEmitter = new Emitter<SharedProcessEvent>();
|
private readonly onStateEmitter = new Emitter<SharedProcessEvent>();
|
||||||
public readonly onState = this.onStateEmitter.event;
|
public readonly onState = this.onStateEmitter.event;
|
||||||
private readonly retryName = "Shared process";
|
private readonly retryName = "Shared process";
|
||||||
|
private readonly logger = logger.named("shared");
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
private readonly userDataDir: string,
|
private readonly userDataDir: string,
|
||||||
@ -65,12 +66,34 @@ export class SharedProcess {
|
|||||||
state: SharedProcessState.Starting,
|
state: SharedProcessState.Starting,
|
||||||
});
|
});
|
||||||
let resolved: boolean = false;
|
let resolved: boolean = false;
|
||||||
|
const maybeStop = (error: string): void => {
|
||||||
|
if (resolved) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.setState({
|
||||||
|
error,
|
||||||
|
state: SharedProcessState.Stopped,
|
||||||
|
});
|
||||||
|
if (!this.activeProcess) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.activeProcess.kill();
|
||||||
|
};
|
||||||
this.activeProcess = forkModule("vs/code/electron-browser/sharedProcess/sharedProcessMain", [], {
|
this.activeProcess = forkModule("vs/code/electron-browser/sharedProcess/sharedProcessMain", [], {
|
||||||
env: {
|
env: {
|
||||||
VSCODE_ALLOW_IO: "true",
|
VSCODE_ALLOW_IO: "true",
|
||||||
VSCODE_LOGS: process.env.VSCODE_LOGS,
|
VSCODE_LOGS: process.env.VSCODE_LOGS,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
if (this.logger.level <= Level.Trace) {
|
||||||
|
this.activeProcess.stdout.on("data", (data) => {
|
||||||
|
this.logger.trace(() => ["stdout", field("data", data.toString())]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.activeProcess.on("error", (error) => {
|
||||||
|
this.logger.error("error", field("error", error));
|
||||||
|
maybeStop(error.message);
|
||||||
|
});
|
||||||
this.activeProcess.on("exit", (err) => {
|
this.activeProcess.on("exit", (err) => {
|
||||||
if (this._state !== SharedProcessState.Stopped) {
|
if (this._state !== SharedProcessState.Stopped) {
|
||||||
this.setState({
|
this.setState({
|
||||||
@ -92,7 +115,7 @@ export class SharedProcess {
|
|||||||
"user-data-dir": this.userDataDir,
|
"user-data-dir": this.userDataDir,
|
||||||
"extensions-dir": extensionsDir,
|
"extensions-dir": extensionsDir,
|
||||||
},
|
},
|
||||||
logLevel: logger.level,
|
logLevel: this.logger.level,
|
||||||
sharedIPCHandle: this.socketPath,
|
sharedIPCHandle: this.socketPath,
|
||||||
};
|
};
|
||||||
this.ipcHandler!.send("handshake:hey there", "", data);
|
this.ipcHandler!.send("handshake:hey there", "", data);
|
||||||
@ -105,16 +128,8 @@ export class SharedProcess {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
this.activeProcess.stderr.on("data", (data) => {
|
this.activeProcess.stderr.on("data", (data) => {
|
||||||
if (!resolved) {
|
this.logger.error("stderr", field("data", data.toString()));
|
||||||
this.setState({
|
maybeStop(data.toString());
|
||||||
error: data.toString(),
|
|
||||||
state: SharedProcessState.Stopped,
|
|
||||||
});
|
|
||||||
if (!this.activeProcess) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.activeProcess.kill();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user