@nxtedition/lib 17.2.7 → 17.2.9

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/app.js CHANGED
@@ -129,23 +129,24 @@ export function makeApp(appConfig, onTerminate) {
129
129
  base: loggerConfig?.base ? { ...loggerConfig.base } : {},
130
130
  })
131
131
 
132
- destroyers.push(
133
- () =>
134
- new Promise((resolve, reject) =>
135
- logger.flush((err) => (err ? reject(err) : resolve(null))),
136
- ),
137
- )
132
+ destroyers.push(() => {
133
+ try {
134
+ logger.flushSync()
135
+ } catch (err) {
136
+ console.error(err)
137
+ }
138
+ })
138
139
  }
139
140
 
140
141
  let terminated = false
141
- const terminate = async () => {
142
+ const terminate = async (reason) => {
142
143
  if (terminated) {
143
144
  return
144
145
  }
145
146
 
146
147
  terminated = true
147
148
 
148
- logger.info('terminate')
149
+ logger.info({ reason }, 'terminate')
149
150
 
150
151
  ac.abort()
151
152
 
@@ -157,11 +158,11 @@ export function makeApp(appConfig, onTerminate) {
157
158
  }
158
159
  }
159
160
 
160
- for (const { reason } of await Promise.allSettled(
161
+ for (const { reason: err } of await Promise.allSettled(
161
162
  destroyers.filter(Boolean).map((fn) => fn(logger)),
162
163
  )) {
163
- if (reason) {
164
- logger.error({ err: reason }, 'shutdown error')
164
+ if (err) {
165
+ logger.error({ err }, 'shutdown error')
165
166
  }
166
167
  }
167
168
 
@@ -176,17 +177,17 @@ export function makeApp(appConfig, onTerminate) {
176
177
  }
177
178
 
178
179
  process
179
- .on('beforeExit', terminate)
180
- .on('SIGINT', terminate)
181
- .on('SIGTERM', terminate)
182
- .on('uncaughtExceptionMonitor', terminate)
180
+ .on('beforeExit', () => terminate('beforeExit'))
181
+ .on('SIGINT', () => terminate('SIGINT'))
182
+ .on('SIGTERM', () => terminate('SIGTERM'))
183
+ .on('uncaughtExceptionMonitor', () => terminate('uncaughtExceptionMonitor'))
183
184
 
184
185
  logger.debug({ data: JSON.stringify(config, null, 2) }, 'config')
185
186
 
186
187
  if (!isMainThread && parentPort) {
187
188
  parentPort.on('message', ({ type }) => {
188
189
  if (type === 'nxt:worker:terminate') {
189
- terminate()
190
+ terminate('nxt:worker:terminate')
190
191
  }
191
192
  })
192
193
  }
package/logger.js CHANGED
@@ -32,8 +32,12 @@ export function createLogger(
32
32
  let flushing = 0
33
33
  setInterval(() => {
34
34
  if (flushing > 60) {
35
- logger.warn('logger is flushing too slow')
36
- stream.flushSync()
35
+ try {
36
+ logger.warn('logger is flushing too slow')
37
+ stream.flushSync()
38
+ } catch (err) {
39
+ console.error(err)
40
+ }
37
41
  } else {
38
42
  flushing++
39
43
  stream.flush(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "17.2.7",
3
+ "version": "17.2.9",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -89,6 +89,7 @@
89
89
  "nconf": "^0.12.1",
90
90
  "nested-error-stacks": "^2.1.1",
91
91
  "object-hash": "^3.0.0",
92
+ "pino": "^8.17.2",
92
93
  "pino-std-serializers": "^6.2.2",
93
94
  "qs": "^6.11.1",
94
95
  "request-target": "^1.0.2",
@@ -564,16 +564,23 @@ export default function ({ ds, proxify, compiler }) {
564
564
  }
565
565
  `)
566
566
  } catch (err) {
567
- throw Object.assign(new Error(`failed to parse expression ${expression}`), { cause: err })
567
+ return () =>
568
+ rxjs.throwError(
569
+ Object.assign(new Error(`failed to parse expression ${expression}`), { cause: err }),
570
+ )
568
571
  }
569
572
 
570
573
  const context = vm.createContext({ ...globals })
571
574
 
572
575
  return (args) =>
573
576
  new rxjs.Observable((o) => {
574
- const exp = new Expression(context, script, expression, args, o)
575
- return () => {
576
- exp._destroy()
577
+ try {
578
+ const exp = new Expression(context, script, expression, args, o)
579
+ return () => {
580
+ exp._destroy()
581
+ }
582
+ } catch (err) {
583
+ o.error(err)
577
584
  }
578
585
  })
579
586
  })