serverless-offline 11.0.1 → 11.0.3

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.3",
5
5
  "description": "Emulate AWS λ and API Gateway locally when developing your Serverless project",
6
6
  "license": "MIT",
7
7
  "exports": {
@@ -86,9 +86,9 @@
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.1230.0",
90
90
  "boxen": "^7.0.0",
91
- "chalk": "^5.0.1",
91
+ "chalk": "^5.1.0",
92
92
  "execa": "^6.1.0",
93
93
  "fs-extra": "^10.1.0",
94
94
  "java-invoke-local": "0.0.6",
@@ -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,31 +299,38 @@ export default class LambdaFunction {
307
299
 
308
300
  this.#startExecutionTimer()
309
301
 
310
- this.#handlerRunDone = false
311
-
312
- const result = await Promise.race([
313
- this.#handlerRunner.run(this.#event, context),
314
- ...(this.#noTimeout ? [] : [this.#timeoutAndTerminate()]),
315
- ])
316
-
317
- this.#handlerRunDone = true
318
-
319
- this.#stopExecutionTimer()
320
-
321
- // TEMP TODO FIXME find better solution
322
- if (!this.#handlerRunner.isDockerRunner()) {
323
- log.notice(
324
- `(λ: ${
325
- this.#functionKey
326
- }) RequestId: ${requestId} Duration: ${this.#executionTimeInMillis().toFixed(
327
- 2,
328
- )} ms Billed Duration: ${this.#billedExecutionTimeInMillis()} ms`,
329
- )
302
+ let result
303
+
304
+ try {
305
+ result = await Promise.race([
306
+ this.#handlerRunner.run(this.#event, context),
307
+ ...(this.#noTimeout ? [] : [this.#timeoutAndTerminate()]),
308
+ ])
309
+
310
+ this.#stopExecutionTimer()
311
+
312
+ // TEMP TODO FIXME find better solution
313
+ if (!this.#handlerRunner.isDockerRunner()) {
314
+ log.notice(
315
+ `(λ: ${
316
+ this.#functionKey
317
+ }) RequestId: ${requestId} Duration: ${this.#executionTimeInMillis().toFixed(
318
+ 2,
319
+ )} ms Billed Duration: ${this.#billedExecutionTimeInMillis()} ms`,
320
+ )
321
+ }
322
+ } catch (err) {
323
+ if (err instanceof LambdaTimeoutError) {
324
+ await this.#handlerRunner.cleanup()
325
+ }
326
+
327
+ throw err
328
+ } finally {
329
+ this.#status = 'IDLE'
330
+
331
+ this.#startIdleTimer()
330
332
  }
331
333
 
332
- this.#status = 'IDLE'
333
- this.#startIdleTimer()
334
-
335
334
  return result
336
335
  }
337
336
  }
@@ -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
  {