You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The CLI will crash if a function throws a non Error type. It is good practice to always throw an Error type but it is not always guaranteed. Developers might throw custom error types, their own objects, or even (in our case) a simple string. This is perhaps not great engineering but it happens. When that non-standard error type is thrown inside a Netlify function it crashes the CLI as follows:
TypeError: Cannot read properties of undefined (reading 'map')
at getNormalizedError (file:///Users/tdbit/.nvm/versions/node/v20.9.0/lib/node_modules/netlify-cli/dist/lib/functions/synchronous.js:88:41)
at handleSynchronousFunction (file:///Users/tdbit/.nvm/versions/node/v20.9.0/lib/node_modules/netlify-cli/dist/lib/functions/synchronous.js:33:23)
at handler (file:///Users/tdbit/.nvm/versions/node/v20.9.0/lib/node_modules/netlify-cli/dist/lib/functions/server.js:203:13)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
System:
OS: macOS 14.5
CPU: (10) arm64 Apple M1 Max
Binaries:
Node: 20.9.0 - ~/.nvm/versions/node/v20.9.0/bin/node
Yarn: 1.22.22 - /opt/homebrew/bin/yarn
npm: 10.1.0 - ~/.nvm/versions/node/v20.9.0/bin/npm
Browsers:
Chrome: 126.0.6478.127
Safari: 17.5
npmGlobalPackages:
netlify-cli: 17.33.0
This is because getNormalizedError assumes the error will have a .stackTrace property.
Steps to reproduce
Add new Netlify function baderror.js to project:
export async function handler(event, context) {
throw "What?"
}
Describe the bug
The CLI will crash if a function throws a non
Error
type. It is good practice to always throw anError
type but it is not always guaranteed. Developers might throw custom error types, their own objects, or even (in our case) a simple string. This is perhaps not great engineering but it happens. When that non-standard error type is thrown inside a Netlify function it crashes the CLI as follows:This is because
getNormalizedError
assumes the error will have a.stackTrace
property.Steps to reproduce
baderror.js
to project:netlify dev
Configuration
No response
Environment
System:
OS: macOS 14.5
CPU: (10) arm64 Apple M1 Max
Memory: 5.24 GB / 64.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.9.0 - ~/.nvm/versions/node/v20.9.0/bin/node
Yarn: 1.22.22 - /opt/homebrew/bin/yarn
npm: 10.1.0 - ~/.nvm/versions/node/v20.9.0/bin/npm
npmGlobalPackages:
netlify-cli: 17.33.0
The text was updated successfully, but these errors were encountered: