Skip to content

fix: show errors thrown by functions that aren't Error instances - #10008

Draft
kuldeepsinh19 wants to merge 1 commit into
netlify:mainfrom
kuldeepsinh19:fix/6215-custom-error-without-stack
Draft

kuldeepsinh19 wants to merge 1 commit into
netlify:mainfrom
kuldeepsinh19:fix/6215-custom-error-without-stack

Conversation

@kuldeepsinh19

Copy link
Copy Markdown

Summary

Fixes #6215

When a function throws something that isn't an Error instance, such as airtable.js's AirtableError ({ error, message, statusCode }) or a plain string, netlify dev / functions:serve doesn't show the function's error. Instead, the request fails inside the CLI:

TypeError: Cannot read properties of undefined (reading 'map')
    at getNormalizedError (src/lib/functions/synchronous.ts:127:39)
    at handleSynchronousFunction (src/lib/functions/synchronous.ts:42:19)

and the response is Express's default error page with that stack trace.

lambda-local (2.2.0, build/lib/context.js) converts only Error instances into { errorType, errorMessage, stackTrace }, and leaves out stackTrace when the error has no stack. Every other thrown value is passed through unchanged. getNormalizedError() assumed all three properties were always there.

Changes:

  • getNormalizedError() (synchronous.ts) takes unknown. It falls back to name/message (or the value itself for a string, inspect() otherwise) and uses an empty stack trace when there's none. Error instances and lambda-local's errors are handled as before.
  • formatLambdaError() (utils.ts, used for scheduled and background functions) also threw on a thrown string (Cannot use 'in' operator to search for 'errorType' in boom), so it now handles non-object values too.

With the repro from the issue (an AirtableError-like throw), functions:serve now returns a 500 with Error: Could not find what you are looking for and logs Function hello has returned an error: Could not find what you are looking for.

Tests:

  • New tests/unit/lib/functions/synchronous.test.ts calls handleSynchronousFunction with an Error, a lambda-local error, a lambda-local error without a stack trace, a non-Error object (JSON and HTML responses) and a string. The last 3 shapes fail on main with the error above.
  • New case in scheduled.test.ts for a thrown string. It fails on main with the in error.
  • npm run test:unit (849 tests), npm run typecheck, eslint and oxfmt --check on the changed files pass (Node 24, in a container). I didn't run the integration suites.

This change was written with help from an AI coding assistant (Claude Code). I've reviewed every line and can explain any of it.


lambda-local only converts Error instances into its { errorType,
errorMessage, stackTrace } shape, and leaves out stackTrace when the
error has no stack. Anything else a function throws (a custom error
object that doesn't extend Error, or a string) is passed through as is,
so getNormalizedError() failed with "Cannot read properties of undefined
(reading 'map')" and the function's error was never shown.
formatLambdaError(), used for scheduled and background functions, threw
on a thrown string for the same reason.

Fixes netlify#6215
@coderabbitai

coderabbitai Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

netlify dev crashes if function throws custom error with no stackTrace property

1 participant