serverless-offline 11.0.1 → 11.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "dedicatedTo": "Blue, a great migrating bird.",
3
3
  "name": "serverless-offline",
4
- "version": "11.0.1",
4
+ "version": "11.0.2",
5
5
  "description": "Emulate AWS λ and API Gateway locally when developing your Serverless project",
6
6
  "license": "MIT",
7
7
  "exports": {
@@ -86,7 +86,7 @@
86
86
  "@hapi/h2o2": "^10.0.0",
87
87
  "@hapi/hapi": "^20.2.2",
88
88
  "@serverless/utils": "^6.7.0",
89
- "aws-sdk": "^2.1225.0",
89
+ "aws-sdk": "^2.1227.0",
90
90
  "boxen": "^7.0.0",
91
91
  "chalk": "^5.0.1",
92
92
  "execa": "^6.1.0",
@@ -0,0 +1 @@
1
+ export default class LambdaTimeoutError extends Error {}
@@ -0,0 +1,2 @@
1
+ // eslint-disable-next-line import/prefer-default-export
2
+ export { default as LambdaTimeoutError } from './LambdaTimeoutError.js'
@@ -912,7 +912,7 @@ export default class HttpServer {
912
912
 
913
913
  this.#apiKeysValues.add(apiKey)
914
914
 
915
- log.notice(`Key with token: ${apiKey}`)
915
+ log.notice(`Key with token: '${apiKey}'`)
916
916
  }
917
917
  }
918
918
  }
@@ -104,8 +104,6 @@ export default class LambdaProxyIntegrationEvent {
104
104
  ) {
105
105
  headers['Content-Type'] = 'application/json'
106
106
  }
107
- } else if (typeof body === 'undefined' || body === '') {
108
- body = null
109
107
  }
110
108
 
111
109
  // clone own props
@@ -87,8 +87,6 @@ export default class LambdaProxyIntegrationEventV2 {
87
87
  if (!headers['content-type']) {
88
88
  headers['content-type'] = 'application/json'
89
89
  }
90
- } else if (typeof body === 'undefined' || body === '') {
91
- body = null
92
90
  }
93
91
 
94
92
  // clone own props
@@ -14,6 +14,7 @@ import {
14
14
  DEFAULT_LAMBDA_TIMEOUT,
15
15
  supportedRuntimes,
16
16
  } from '../config/index.js'
17
+ import { LambdaTimeoutError } from '../errors/index.js'
17
18
  import { createUniqueId } from '../utils/index.js'
18
19
 
19
20
  const { ceil } = Math
@@ -40,8 +41,6 @@ export default class LambdaFunction {
40
41
 
41
42
  #handler = null
42
43
 
43
- #handlerRunDone = false
44
-
45
44
  #handlerRunner = null
46
45
 
47
46
  #idleTimeStarted = null
@@ -281,14 +280,7 @@ export default class LambdaFunction {
281
280
  async #timeoutAndTerminate() {
282
281
  await setTimeoutPromise(this.#timeout)
283
282
 
284
- // if the handler has finished before the timeout don't terminate
285
- if (this.#handlerRunDone) {
286
- return
287
- }
288
-
289
- await this.#handlerRunner.cleanup()
290
-
291
- throw new Error('Lambda timeout.')
283
+ throw new LambdaTimeoutError('Lambda timeout.')
292
284
  }
293
285
 
294
286
  async runHandler() {
@@ -307,14 +299,20 @@ export default class LambdaFunction {
307
299
 
308
300
  this.#startExecutionTimer()
309
301
 
310
- this.#handlerRunDone = false
302
+ let result
311
303
 
312
- const result = await Promise.race([
313
- this.#handlerRunner.run(this.#event, context),
314
- ...(this.#noTimeout ? [] : [this.#timeoutAndTerminate()]),
315
- ])
304
+ try {
305
+ result = await Promise.race([
306
+ this.#handlerRunner.run(this.#event, context),
307
+ ...(this.#noTimeout ? [] : [this.#timeoutAndTerminate()]),
308
+ ])
309
+ } catch (err) {
310
+ if (err instanceof LambdaTimeoutError) {
311
+ await this.#handlerRunner.cleanup()
312
+ }
316
313
 
317
- this.#handlerRunDone = true
314
+ throw err
315
+ }
318
316
 
319
317
  this.#stopExecutionTimer()
320
318
 
@@ -330,6 +328,7 @@ export default class LambdaFunction {
330
328
  }
331
329
 
332
330
  this.#status = 'IDLE'
331
+
333
332
  this.#startIdleTimer()
334
333
 
335
334
  return result
@@ -2,7 +2,7 @@ import { env } from 'node:process'
2
2
  import { parentPort, workerData } from 'node:worker_threads'
3
3
  import InProcessRunner from '../in-process-runner/index.js'
4
4
 
5
- const { functionKey, handler, servicePath, timeout, codeDir } = workerData
5
+ const { codeDir, functionKey, handler, servicePath, timeout } = workerData
6
6
 
7
7
  const inProcessRunner = new InProcessRunner(
8
8
  {