Repository navigation
fix: show errors thrown by functions that aren't Error instances - #10008
Draft
kuldeepsinh19 wants to merge 1 commit into
Draft
kuldeepsinh19 wants to merge 1 commit into
kuldeepsinh19 wants to merge 1 commit into
Conversation
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
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
CodeRabbit Verify
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #6215
When a function throws something that isn't an
Errorinstance, such as airtable.js'sAirtableError({ error, message, statusCode }) or a plain string,netlify dev/functions:servedoesn't show the function's error. Instead, the request fails inside the CLI:and the response is Express's default error page with that stack trace.
lambda-local (2.2.0,
build/lib/context.js) converts onlyErrorinstances into{ errorType, errorMessage, stackTrace }, and leaves outstackTracewhen the error has nostack. Every other thrown value is passed through unchanged.getNormalizedError()assumed all three properties were always there.Changes:
getNormalizedError()(synchronous.ts) takesunknown. It falls back toname/message(or the value itself for a string,inspect()otherwise) and uses an empty stack trace when there's none.Errorinstances 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:servenow returns a 500 withError: Could not find what you are looking forand logsFunction hello has returned an error: Could not find what you are looking for.Tests:
tests/unit/lib/functions/synchronous.test.tscallshandleSynchronousFunctionwith anError, a lambda-local error, a lambda-local error without a stack trace, a non-Errorobject (JSON and HTML responses) and a string. The last 3 shapes fail onmainwith the error above.scheduled.test.tsfor a thrown string. It fails onmainwith theinerror.npm run test:unit(849 tests),npm run typecheck,eslintandoxfmt --checkon 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.
netlify devcrashes if function throws custom error with nostackTraceproperty #6215)