Repository navigation
fix: show errors thrown by functions that aren't Error instances - #10008
kuldeepsinh19 wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
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
6fbf895 to
6748e84
Compare
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)