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

Commit ada6d8c

Browse files
Merge branch 'fix/unh-error' into main
2 parents ba3b02e + 4fa3bab commit ada6d8c

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
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 & 0 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,6 +42,7 @@ class ProcessHelper extends messenger_1.Messenger {
3842
this.start();
3943
};
4044
this.childProcess.on('exit', this.autoRestartListener);
45+
this.childProcess.on('error', this.errorHandler);
4146
}
4247
this.connect(this.childProcess);
4348
}
@@ -48,6 +53,7 @@ class ProcessHelper extends messenger_1.Messenger {
4853
if (this.childProcess.pid) {
4954
this.disconnect();
5055
this.childProcess.off('exit', this.autoRestartListener);
56+
this.childProcess.off('error', this.errorHandler);
5157
this.autoRestartListener = undefined;
5258
this.childProcess.kill('SIGTERM');
5359
this.childProcess = undefined;

src/process-helper.ts

Lines changed: 7 additions & 0 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,6 +64,7 @@ export class ProcessHelper extends Messenger {
5964
};
6065

6166
this.childProcess.on('exit', this.autoRestartListener);
67+
this.childProcess.on('error', this.errorHandler);
6268
}
6369

6470
this.connect(this.childProcess);
@@ -72,6 +78,7 @@ export class ProcessHelper extends Messenger {
7278
this.disconnect();
7379

7480
this.childProcess.off('exit', this.autoRestartListener!);
81+
this.childProcess.off('error', this.errorHandler);
7582
this.autoRestartListener = undefined;
7683

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

0 commit comments

Comments
 (0)