serverless-offline 9.2.5 → 9.2.6

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": "9.2.5",
4
+ "version": "9.2.6",
5
5
  "description": "Emulate AWS λ and API Gateway locally when developing your Serverless project",
6
6
  "license": "MIT",
7
7
  "main": "./src/index.js",
@@ -83,6 +83,15 @@ export default class ServerlessOffline {
83
83
  }
84
84
 
85
85
  await Promise.all(eventModules)
86
+
87
+ if (this.#options.useChildProcesses) {
88
+ log.notice()
89
+ log.warning(
90
+ orange(`'--useChildProcesses' is deprecated and will be removed in the next major version. Worker threads, the current default, should provide the same if not an even better developer experience.
91
+ If you are experiencing any issues please let us know: https://github.com/dherault/serverless-offline/issues`),
92
+ )
93
+ log.notice()
94
+ }
86
95
  }
87
96
 
88
97
  async #ready() {
@@ -225,14 +234,6 @@ export default class ServerlessOffline {
225
234
  ...this.#cliOptions,
226
235
  }
227
236
 
228
- if (this.#options.useChildProcesses) {
229
- log.notice()
230
- log.warning(
231
- orange(`'--useChildProcesses' is deprecated and will be removed in the next major version. Worker threads, the current default, should provide the same if not an even better developer experience.
232
- If you are experiencing any issues please let us know: https://github.com/dherault/serverless-offline/issues`),
233
- )
234
- }
235
-
236
237
  // Parse CORS options
237
238
  this.#options.corsAllowHeaders = this.#options.corsAllowHeaders
238
239
  .replace(/\s/g, '')
@@ -123,6 +123,13 @@ export default class HandlerRunner {
123
123
  this.#runner = await this.#loadRunner()
124
124
  }
125
125
 
126
- return this.#runner.run(event, context)
126
+ try {
127
+ return await this.#runner.run(event, context)
128
+ } catch (err) {
129
+ log.error(
130
+ `Unhandled exception in handler '${this.#funOptions.functionKey}'.`,
131
+ )
132
+ throw err
133
+ }
127
134
  }
128
135
  }
@@ -11,8 +11,6 @@ export default class InProcessRunner {
11
11
 
12
12
  #env = null
13
13
 
14
- #functionKey = null
15
-
16
14
  #handler = null
17
15
 
18
16
  #servicePath = null
@@ -20,11 +18,10 @@ export default class InProcessRunner {
20
18
  #timeout = null
21
19
 
22
20
  constructor(funOptions, env) {
23
- const { codeDir, functionKey, handler, servicePath, timeout } = funOptions
21
+ const { codeDir, handler, servicePath, timeout } = funOptions
24
22
 
25
23
  this.#codeDir = codeDir
26
24
  this.#env = env
27
- this.#functionKey = functionKey
28
25
  this.#handler = handler
29
26
  this.#servicePath = servicePath
30
27
  this.#timeout = timeout
@@ -48,7 +45,7 @@ export default class InProcessRunner {
48
45
 
49
46
  let callback
50
47
 
51
- const callbackCalled = new Promise((res, rej) => {
48
+ const callbackWrapper = new Promise((res, rej) => {
52
49
  callback = (err, data) => {
53
50
  if (err === 'Unauthorized') {
54
51
  res('Unauthorized')
@@ -85,29 +82,22 @@ export default class InProcessRunner {
85
82
  },
86
83
  }
87
84
 
88
- let result
89
-
90
85
  // execute (run) handler
91
- try {
92
- result = handler(event, lambdaContext, callback)
93
- } catch {
94
- throw new Error(`Uncaught error in '${this.#functionKey}' handler.`)
95
- }
86
+ // no try/catch so that errors bubble up and are logged with root stack traces
87
+ const result = handler(event, lambdaContext, callback)
96
88
 
97
89
  // // not a Promise, which is not supported by aws
98
90
  // if (result == null || typeof result.then !== 'function') {
99
91
  // throw new Error(`Synchronous function execution is not supported.`)
100
92
  // }
101
93
 
102
- const callbacks = [callbackCalled]
94
+ const responses = [callbackWrapper]
103
95
 
104
96
  // Promise was returned
105
97
  if (result != null && typeof result.then === 'function') {
106
- callbacks.push(result)
98
+ responses.push(result)
107
99
  }
108
100
 
109
- const callbackResult = await Promise.race(callbacks)
110
-
111
- return callbackResult
101
+ return Promise.race(responses)
112
102
  }
113
103
  }