Skip to content

Commit aa3f3e3

Browse files
Better error logging
1 parent 168b3b0 commit aa3f3e3

File tree

3 files changed

+49
-32
lines changed

3 files changed

+49
-32
lines changed

src/frameworks/cdkFramework.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,14 @@ export class CdkFramework implements IFramework {
477477
}
478478
});
479479

480+
// worker.stdout.on('data', (data: Buffer) => {
481+
// Logger.log(`[CDK]`, data.toString());
482+
// });
483+
484+
// worker.stderr.on('data', (data: Buffer) => {
485+
// Logger.error(`[CDK]`, data.toString());
486+
// });
487+
480488
worker.postMessage({
481489
compileOutput: compileCodeFile,
482490
});

src/frameworks/cdkFrameworkWorker.mjs

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,43 @@ Logger.setVerbose(workerData.verbose);
1414
Logger.verbose(`[CDK] [Worker] Started`);
1515

1616
parentPort.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+
});

src/nodeWorker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function startWorker(input: WorkerRequest) {
110110
Logger.log(`[Function ${input.functionId}]`, data.toString());
111111
});
112112
worker.stderr.on('data', (data: Buffer) => {
113-
Logger.log(`[Function ${input.functionId}]`, data.toString());
113+
Logger.error(`[Function ${input.functionId}]`, data.toString());
114114
});
115115
worker.on('exit', () => {
116116
Logger.verbose(

0 commit comments

Comments
 (0)