Skip to content

Commit e7cd9e5

Browse files
authored
fix: actually handle AWS SDK errors as intended (#7184)
* fix: actually handle AWS SDK error as intended * refactor: rename misleading `detectAwsSdkError` * fix: handle non-normalized function invocation errors
1 parent 1b00c77 commit e7cd9e5

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/lib/functions/synchronous.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { LambdaEvent } from 'lambda-local'
88
import { chalk, logPadded, NETLIFYDEVERR } from '../../utils/command-helpers.js'
99
import renderErrorTemplate from '../render-error-template.js'
1010

11-
import { detectAwsSdkError } from './utils.js'
11+
import { warnIfAwsSdkError } from './utils.js'
1212
import type { InvocationError } from './netlify-function.js'
1313

1414
// Annoyingly, `isReadableStream` refines to the `Readable` interface rather than the
@@ -152,8 +152,7 @@ const handleErr = async (
152152
request: express.Request,
153153
response: express.Response,
154154
) => {
155-
// @ts-expect-error -- XXX(serhalp): Expects `error` but passes `err`, so it has never worked. Fixed in stacked PR.
156-
detectAwsSdkError({ err })
155+
warnIfAwsSdkError({ error: err })
157156

158157
const acceptsHtml = request.headers.accept?.includes('text/html') ?? false
159158
const errorString = typeof err === 'string' ? err : formatLambdaLocalError(err, acceptsHtml)

src/lib/functions/utils.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { MISSING_AWS_SDK_WARNING } from '../log.js'
33

44
import type { InvocationError } from './netlify-function.js'
55

6-
// TODO(serhalp): Rename? This doesn't "detect", it maybe logs a warning.
7-
export const detectAwsSdkError = ({ error }: { error: Error | InvocationError | string }): void => {
6+
export const warnIfAwsSdkError = ({ error }: { error: Error | InvocationError | string }): void => {
87
const isAwsSdkError =
98
typeof error === 'object' &&
109
'errorMessage' in error &&
@@ -16,10 +15,10 @@ export const detectAwsSdkError = ({ error }: { error: Error | InvocationError |
1615
}
1716
}
1817

19-
// XXX(serhalp): This appears to be a bug? In the background and scheduled function code paths this can receive plain
20-
// errors, but this is assuming normalized `InvocationError`s only.
2118
export const formatLambdaError = (err: Error | InvocationError): string =>
22-
chalk.red(`${'errorType' in err ? err.errorType : ''}: ${'errorMessage' in err ? err.errorMessage : ''}`)
19+
chalk.red(
20+
`${'errorType' in err ? err.errorType : 'Error'}: ${'errorMessage' in err ? err.errorMessage : err.message}`,
21+
)
2322

2423
// should be equivalent to https://github.com/netlify/proxy/blob/main/pkg/functions/request.go#L105
2524
const exceptionsList = new Set([

0 commit comments

Comments
 (0)