3
3
DEngine ,
4
4
ERROR_SEVERITY ,
5
5
ERROR_STATUS ,
6
- stringifyError
6
+ stringifyError ,
7
7
} from "@dendronhq/common-all" ;
8
8
import { createLogger } from "@dendronhq/common-server" ;
9
9
import { DendronEngineV2 } from "@dendronhq/engine-server" ;
@@ -57,7 +57,7 @@ export enum SubProcessExitType {
57
57
SIGINT = "SIGINT" ,
58
58
SIGURS1 = "SIGUSR1" ,
59
59
SIGURS2 = "SIGUSR2" ,
60
- UNCAUGHT_EXCEPTION = "uncaughtException"
60
+ UNCAUGHT_EXCEPTION = "uncaughtException" ,
61
61
}
62
62
export class ServerUtils {
63
63
static onProcessExit ( {
@@ -74,7 +74,9 @@ export class ServerUtils {
74
74
subprocess . on ( "SIGUSR2" , ( ) => cb ( SubProcessExitType . SIGURS2 ) ) ;
75
75
76
76
//catches uncaught exceptions
77
- subprocess . on ( "uncaughtException" , ( ) => cb ( SubProcessExitType . UNCAUGHT_EXCEPTION ) ) ;
77
+ subprocess . on ( "uncaughtException" , ( ) =>
78
+ cb ( SubProcessExitType . UNCAUGHT_EXCEPTION )
79
+ ) ;
78
80
}
79
81
80
82
/**
@@ -160,9 +162,12 @@ export class ServerUtils {
160
162
nextStaticRoot,
161
163
port,
162
164
} : ServerArgs ) : Promise < { port : number ; subprocess : ExecaChildProcess } > {
163
- const logger = createLogger ( "execServer" , path . join ( logPath , "dendron.log" ) ) ;
165
+ const logger = createLogger (
166
+ "execServer" ,
167
+ path . join ( logPath , "dendron.log" )
168
+ ) ;
164
169
return new Promise ( ( resolve , reject ) => {
165
- logger . info ( { state : "enter" } )
170
+ logger . info ( { state : "enter" } ) ;
166
171
const subprocess = execa . node ( scriptPath , {
167
172
env : {
168
173
LOG_PATH : logPath ,
@@ -171,32 +176,34 @@ export class ServerUtils {
171
176
NEXT_STATIC_ROOT : nextStaticRoot ,
172
177
} as SERVER_ENV ,
173
178
} ) ;
174
- logger . info ( { state : "post:exec.node" } )
179
+ logger . info ( { state : "post:exec.node" } ) ;
175
180
subprocess . on ( "close" , ( code ) => {
176
- logger . error ( { state : "close" } )
177
- reject ( new DendronError ( { message : "close" , payload : { code} } ) ) ;
181
+ logger . error ( { state : "close" } ) ;
182
+ reject ( new DendronError ( { message : "close" , payload : { code } } ) ) ;
178
183
} ) ;
179
184
subprocess . on ( "disconnect" , ( ) => {
180
- logger . error ( { state : "disconnect" } )
181
- reject ( new DendronError ( { message : "disconnect" } ) ) ;
185
+ logger . error ( { state : "disconnect" } ) ;
186
+ reject ( new DendronError ( { message : "disconnect" } ) ) ;
182
187
} ) ;
183
188
subprocess . on ( "exit" , ( code ) => {
184
- logger . error ( { state : "exit" } )
185
- reject ( new DendronError ( { message : "exit" , payload : { code} } ) ) ;
189
+ logger . error ( { state : "exit" } ) ;
190
+ reject ( new DendronError ( { message : "exit" , payload : { code } } ) ) ;
186
191
} ) ;
187
192
subprocess . on ( "error" , ( err ) => {
188
- logger . error ( { state : "error" , payload : err } )
189
- reject ( new DendronError ( { message : "error" , payload : stringifyError ( err ) } ) ) ;
193
+ logger . error ( { state : "error" , payload : err } ) ;
194
+ reject (
195
+ new DendronError ( { message : "error" , payload : stringifyError ( err ) } )
196
+ ) ;
190
197
} ) ;
191
198
subprocess . on ( "message" , ( message ) => {
192
- logger . info ( { state : "message" , message} )
199
+ logger . info ( { state : "message" , message } ) ;
193
200
const port = parseInt ( message as string , 10 ) ;
194
201
if ( port <= 0 ) {
195
202
reject ( {
196
203
error : new DendronError ( {
197
204
message : "port is smaller than 0" ,
198
205
severity : ERROR_SEVERITY . FATAL ,
199
- } )
206
+ } ) ,
200
207
} ) ;
201
208
}
202
209
resolve ( { port, subprocess } ) ;
0 commit comments