Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Commit 4fa3bab

Browse files
changed error handler to log the error.
1 parent c541132 commit 4fa3bab

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

dist/process-helper.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export declare class ProcessHelper extends Messenger {
66
private env;
77
private childProcess;
88
private autoRestartListener;
9+
private errorHandler;
910
constructor(forkPath: string);
1011
setEnv(env: any): void;
1112
isStarted(): boolean;

dist/process-helper.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ class ProcessHelper extends messenger_1.Messenger {
77
constructor(forkPath) {
88
super();
99
this.forkPath = forkPath;
10+
this.errorHandler = (...args) => {
11+
console.error('child process error', ...args);
12+
this.autoRestartListener?.(...args);
13+
};
1014
ProcessHelper.instances.add(this);
1115
}
1216
static killAll() {
@@ -38,7 +42,7 @@ class ProcessHelper extends messenger_1.Messenger {
3842
this.start();
3943
};
4044
this.childProcess.on('exit', this.autoRestartListener);
41-
this.childProcess.on('error', this.autoRestartListener);
45+
this.childProcess.on('error', this.errorHandler);
4246
}
4347
this.connect(this.childProcess);
4448
}
@@ -49,7 +53,7 @@ class ProcessHelper extends messenger_1.Messenger {
4953
if (this.childProcess.pid) {
5054
this.disconnect();
5155
this.childProcess.off('exit', this.autoRestartListener);
52-
this.childProcess.off('error', this.autoRestartListener);
56+
this.childProcess.off('error', this.errorHandler);
5357
this.autoRestartListener = undefined;
5458
this.childProcess.kill('SIGTERM');
5559
this.childProcess = undefined;

src/process-helper.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ export class ProcessHelper extends Messenger {
1818

1919
private autoRestartListener: undefined | ((...args: any[])=> void);
2020

21+
private errorHandler = (...args: any[]) => {
22+
console.error('child process error', ...args);
23+
this.autoRestartListener?.(...args);
24+
};
25+
2126
constructor(private readonly forkPath: string) {
2227
super();
2328

@@ -59,7 +64,7 @@ export class ProcessHelper extends Messenger {
5964
};
6065

6166
this.childProcess.on('exit', this.autoRestartListener);
62-
this.childProcess.on('error', this.autoRestartListener);
67+
this.childProcess.on('error', this.errorHandler);
6368
}
6469

6570
this.connect(this.childProcess);
@@ -73,7 +78,7 @@ export class ProcessHelper extends Messenger {
7378
this.disconnect();
7479

7580
this.childProcess.off('exit', this.autoRestartListener!);
76-
this.childProcess.off('error', this.autoRestartListener!);
81+
this.childProcess.off('error', this.errorHandler);
7782
this.autoRestartListener = undefined;
7883

7984
this.childProcess.kill('SIGTERM');

0 commit comments

Comments
 (0)