@@ -48,6 +48,7 @@ import {
48
48
Bools ,
49
49
Logger ,
50
50
LoggerProvider ,
51
+ newRex ,
51
52
Servers ,
52
53
} from "@hyperledger/cactus-common" ;
53
54
@@ -248,17 +249,17 @@ export class ApiServer {
248
249
}
249
250
250
251
return { addressInfoCockpit, addressInfoApi, addressInfoGrpc } ;
251
- } catch ( ex ) {
252
- const errorMessage = ` Failed to start ApiServer: ${ ex . stack } ` ;
253
- this . log . error ( errorMessage ) ;
252
+ } catch ( ex1 : unknown ) {
253
+ const context = " Failed to start ApiServer" ;
254
+ this . log . error ( context , ex1 ) ;
254
255
this . log . error ( `Attempting shutdown...` ) ;
255
256
try {
256
257
await this . shutdown ( ) ;
257
258
this . log . info ( `Server shut down after crash OK` ) ;
258
- } catch ( ex ) {
259
- this . log . error ( ApiServer . E_POST_CRASH_SHUTDOWN , ex ) ;
259
+ } catch ( ex2 : unknown ) {
260
+ this . log . error ( ApiServer . E_POST_CRASH_SHUTDOWN , ex2 ) ;
260
261
}
261
- throw new Error ( errorMessage ) ;
262
+ throw newRex ( context , ex1 ) ;
262
263
}
263
264
}
264
265
@@ -304,11 +305,11 @@ export class ApiServer {
304
305
await this . getPluginImportsCount ( ) ,
305
306
) ;
306
307
return this . pluginRegistry ;
307
- } catch ( e ) {
308
+ } catch ( ex : unknown ) {
308
309
this . pluginRegistry = new PluginRegistry ( { plugins : [ ] } ) ;
309
- const errorMessage = ` Failed init PluginRegistry: ${ e . stack } ` ;
310
- this . log . error ( errorMessage ) ;
311
- throw new Error ( errorMessage ) ;
310
+ const context = " Failed to init PluginRegistry" ;
311
+ this . log . debug ( context , ex ) ;
312
+ throw newRex ( context , ex ) ;
312
313
}
313
314
}
314
315
@@ -368,15 +369,10 @@ export class ApiServer {
368
369
await plugin . onPluginInit ( ) ;
369
370
370
371
return plugin ;
371
- } catch ( error ) {
372
- const errorMessage = `${ fnTag } failed instantiating plugin '${ packageName } ' with the instanceId '${ options . instanceId } '` ;
373
- this . log . error ( errorMessage , error ) ;
374
-
375
- if ( error instanceof Error ) {
376
- throw new RuntimeError ( errorMessage , error ) ;
377
- } else {
378
- throw new RuntimeError ( errorMessage , JSON . stringify ( error ) ) ;
379
- }
372
+ } catch ( ex : unknown ) {
373
+ const context = `${ fnTag } failed instantiating plugin '${ packageName } ' with the instanceId '${ options . instanceId } '` ;
374
+ this . log . debug ( context , ex ) ;
375
+ throw newRex ( context , ex ) ;
380
376
}
381
377
}
382
378
@@ -397,10 +393,10 @@ export class ApiServer {
397
393
try {
398
394
await fs . mkdirp ( pluginPackageDir ) ;
399
395
this . log . debug ( `${ pkgName } plugin package dir: %o` , pluginPackageDir ) ;
400
- } catch ( ex ) {
401
- const errorMessage =
396
+ } catch ( ex : unknown ) {
397
+ const context =
402
398
"Could not create plugin installation directory, check the file-system permissions." ;
403
- throw new RuntimeError ( errorMessage , ex ) ;
399
+ throw newRex ( context , ex ) ;
404
400
}
405
401
try {
406
402
lmify . setPackageManager ( "npm" ) ;
@@ -418,19 +414,15 @@ export class ApiServer {
418
414
// "--ignore-workspace-root-check",
419
415
] ) ;
420
416
this . log . debug ( "%o install result: %o" , pkgName , out ) ;
421
- if ( out . exitCode !== 0 ) {
422
- throw new RuntimeError ( "Non-zero exit code: " , JSON . stringify ( out ) ) ;
417
+ if ( out ?. exitCode && out . exitCode !== 0 ) {
418
+ const eMsg = "Non-zero exit code returned by lmify.install() indicating that the underlying npm install OS process had encountered a problem:" ;
419
+ throw newRex ( eMsg , out ) ;
423
420
}
424
421
this . log . info ( `Installed ${ pkgName } OK` ) ;
425
- } catch ( ex ) {
426
- const errorMessage = `${ fnTag } failed installing plugin '${ pkgName } ` ;
427
- this . log . error ( errorMessage , ex ) ;
428
-
429
- if ( ex instanceof Error ) {
430
- throw new RuntimeError ( errorMessage , ex ) ;
431
- } else {
432
- throw new RuntimeError ( errorMessage , JSON . stringify ( ex ) ) ;
433
- }
422
+ } catch ( ex : unknown ) {
423
+ const context = `${ fnTag } failed installing plugin '${ pkgName } ` ;
424
+ this . log . debug ( ex , context ) ;
425
+ throw newRex ( context , ex ) ;
434
426
}
435
427
}
436
428
@@ -451,24 +443,25 @@ export class ApiServer {
451
443
this . log . info ( `Stopped ${ webServicesShutdown . length } WS plugin(s) OK` ) ;
452
444
453
445
if ( this . httpServerApi ?. listening ) {
454
- this . log . info ( `Closing HTTP server of the API...` ) ;
446
+ this . log . info ( `Closing Cacti HTTP server of the API...` ) ;
455
447
await Servers . shutdown ( this . httpServerApi ) ;
456
448
this . log . info ( `Close HTTP server of the API OK` ) ;
457
449
}
458
450
459
451
if ( this . httpServerCockpit ?. listening ) {
460
- this . log . info ( `Closing HTTP server of the cockpit ...` ) ;
452
+ this . log . info ( `Closing Cacti HTTP server of the cockpit ...` ) ;
461
453
await Servers . shutdown ( this . httpServerCockpit ) ;
462
454
this . log . info ( `Close HTTP server of the cockpit OK` ) ;
463
455
}
464
456
465
457
if ( this . grpcServer ) {
466
- this . log . info ( `Closing gRPC server ...` ) ;
458
+ this . log . info ( `Closing Cacti gRPC server ...` ) ;
467
459
await new Promise < void > ( ( resolve , reject ) => {
468
460
this . grpcServer . tryShutdown ( ( ex ?: Error ) => {
469
461
if ( ex ) {
470
- this . log . error ( "Failed to shut down gRPC server: " , ex ) ;
471
- reject ( ex ) ;
462
+ const eMsg = "Failed to shut down gRPC server of the Cacti API server." ;
463
+ this . log . debug ( eMsg , ex ) ;
464
+ reject ( newRex ( eMsg , ex ) ) ;
472
465
} else {
473
466
resolve ( ) ;
474
467
}
0 commit comments