@@ -14,38 +14,43 @@ Logger.setVerbose(workerData.verbose);
1414Logger . verbose ( `[CDK] [Worker] Started` ) ;
1515
1616parentPort . on ( 'message' , async ( data ) => {
17- // this is global variable to store the data from the CDK code once it is executed
18- global . lambdas = [ ] ;
19-
20- Logger . verbose ( `[Worker ${ workerData . workerId } ] Received message` , data ) ;
21-
22- // execute code to get the data into global.lambdas
23- await fixCdkPaths ( workerData . awsCdkLibPath ) ;
24- await import ( data . compileOutput ) ;
25-
26- if ( ! global . lambdas || global . lambdas ?. length === 0 ) {
27- throw new Error ( 'No Lambda functions found in the CDK code' ) ;
17+ try {
18+ // this is global variable to store the data from the CDK code once it is executed
19+ global . lambdas = [ ] ;
20+
21+ Logger . verbose ( `[Worker ${ workerData . workerId } ] Received message` , data ) ;
22+
23+ // execute code to get the data into global.lambdas
24+ await fixCdkPaths ( workerData . awsCdkLibPath ) ;
25+ await import ( data . compileOutput ) ;
26+
27+ if ( ! global . lambdas || global . lambdas ?. length === 0 ) {
28+ throw new Error ( 'No Lambda functions found in the CDK code' ) ;
29+ }
30+
31+ const lambdas = global . lambdas . map ( ( lambda ) => ( {
32+ handler : lambda . handler ,
33+ stackName : lambda . stackName ,
34+ codePath : lambda . codePath ,
35+ code : {
36+ path : lambda . code ?. path ,
37+ } ,
38+ cdkPath : lambda . node . defaultChild . node . path ,
39+ bundling : {
40+ ...lambda . bundling ,
41+ commandHooks : undefined , // can not be serialized
42+ } ,
43+ } ) ) ;
44+
45+ Logger . verbose (
46+ `[CDK] [Worker] Sending found lambdas` ,
47+ JSON . stringify ( lambdas , null , 2 ) ,
48+ ) ;
49+ parentPort . postMessage ( lambdas ) ;
50+ } catch ( error ) {
51+ Logger . error ( `[CDK] [Worker] Error` , error ) ;
52+ throw error ;
2853 }
29-
30- const lambdas = global . lambdas . map ( ( lambda ) => ( {
31- handler : lambda . handler ,
32- stackName : lambda . stackName ,
33- codePath : lambda . codePath ,
34- code : {
35- path : lambda . code ?. path ,
36- } ,
37- cdkPath : lambda . node . defaultChild . node . path ,
38- bundling : {
39- ...lambda . bundling ,
40- commandHooks : undefined , // can not be serialized
41- } ,
42- } ) ) ;
43-
44- Logger . verbose (
45- `[CDK] [Worker] Sending found lambdas` ,
46- JSON . stringify ( lambdas , null , 2 ) ,
47- ) ;
48- parentPort . postMessage ( lambdas ) ;
4954} ) ;
5055
5156/**
@@ -97,3 +102,7 @@ async function fixCdkPaths(awsCdkLibPath) {
97102 exports : pathProxy ,
98103 } ;
99104}
105+
106+ process . on ( 'unhandledRejection' , ( error ) => {
107+ Logger . error ( `[CDK] [Worker] Unhandled Rejection` , error ) ;
108+ } ) ;
0 commit comments