Improve error message due to node version mismatches
Woodz opened this issue · 1 comments
Woodz commented
Expected Behavior
A message that explains that Node (would be good to include version here as well) could not parse the handler code
Actual Behavior
"errorType": "Runtime.UserCodeSyntaxError",
"errorMessage": "SyntaxError: Unexpected token '.'",
"trace": [
"Runtime.UserCodeSyntaxError: SyntaxError: Unexpected token '.'",
" at UserCodeSyntaxError.ExtendedError [as constructor] (/opt/nodejs/node_modules/datadog-lambda-js/runtime/errors.js:113:28)",
" at new UserCodeSyntaxError (/opt/nodejs/node_modules/datadog-lambda-js/runtime/errors.js:147:42)",
" at _loadUserApp (/opt/nodejs/node_modules/datadog-lambda-js/runtime/user-function.js:108:19)",
" at load (/opt/nodejs/node_modules/datadog-lambda-js/runtime/user-function.js:148:19)",
" at Object.<anonymous> (/opt/nodejs/node_modules/datadog-lambda-js/handler.js:65:59)",
" at Module._compile (internal/modules/cjs/loader.js:999:30)",
" at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)",
" at Module.load (internal/modules/cjs/loader.js:863:32)",
" at Function.Module._load (internal/modules/cjs/loader.js:708:14)",
" at Module.require (internal/modules/cjs/loader.js:887:19)"
]
}```
## Steps to Reproduce the Problem
1. Create a Lambda handler in JS that uses node v14 and nullish-chaining (`?.`) but runtime is node v12
1. Add DD layer for node v12 and set handler env var to our Lambda handler
1. Test Lambda
## Specifications
- Datadog Lambda Layer version: Datadog-Node12-x | 67
- Node version: v12/14
## Stacktrace
Paste here
astuyve commented
Hi! Today with handler redirection, this is probably as good of an error message as we can get. Unfortunately we're require
-ing the handler and this is the error generated when node can't parse the file.
I do think it's unfortunate that the stack trace flys through Datadog, but I think you can avoid that using NODE_OPTIONS
to bootstrap this library following this method.
Thanks, hope I've helped!