Skip to content

Commit

Permalink
chore(aws-lambda-auto-wrap): extended error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kirrg001 committed Nov 21, 2022
1 parent cbb7d95 commit bfe5b9d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/aws-lambda-auto-wrap/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ function requireTargetHandlerModule(lambdaTaskRoot, targetHandlerModuleFolder, t
} catch (e) {
if ('MODULE_NOT_FOUND' === e.code) {
throw new localUtils.errors.lambda.ImportModuleError(e);
} else if ('ERR_REQUIRE_ESM' === e.code) {
} else if (
'ERR_REQUIRE_ESM' === e.code ||
e.message.indexOf('Cannot use import statement outside a module') !== -1
) {
throw new localUtils.errors.lambda.ImportModuleError(
'Your Lambda function is using an ES module. ' +
"Please use the 'instana-aws-lambda-auto-wrap-esm.handler' as runtime handler."
Expand Down
5 changes: 4 additions & 1 deletion packages/aws-lambda-auto-wrap/test/cjs_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ describe('cjs wrapper', function () {
if (semver.lt(process.versions.node, '12.0.0')) {
expect(e.message).to.eql('SyntaxError: Unexpected identifier');
} else {
expect(e.message).to.eql('SyntaxError: Cannot use import statement outside a module');
expect(e.message).to.eql(
'Your Lambda function is using an ES module. ' +
"Please use the 'instana-aws-lambda-auto-wrap-esm.handler' as runtime handler."
);
}
}

Expand Down

0 comments on commit bfe5b9d

Please sign in to comment.