Skip to content

Commit c6377f5

Browse files
committed
Avoid uncaught exceptions closing the nodejs processes.
1 parent 5270531 commit c6377f5

File tree

10 files changed

+20
-0
lines changed

10 files changed

+20
-0
lines changed

src/OPC-UA-Server/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const AppDefs = require('./app-defs')
3232
const { LoadConfig, getMongoConnectionOptions } = require('./load-config')
3333
let HintMongoIsConnected = true
3434

35+
process.on('uncaughtException', err => Log.log('Uncaught Exception:' + JSON.stringify(err)))
36+
3537
;(async () => {
3638
const jsConfig = LoadConfig() // load and parse config file
3739
Log.levelCurrent = jsConfig.LogLevel

src/alarm_beep/alarm_beep.js

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const { MongoClient } = require('mongodb')
2727
const { setInterval } = require('timers')
2828
const sys = require('child_process')
2929

30+
process.on('uncaughtException', err => Log.log('Uncaught Exception:' + JSON.stringify(err)))
31+
3032
const WavFilesWin = [
3133
'c:\\windows\\media\\Windows Default.wav',
3234
'c:\\windows\\media\\Windows Background.wav',

src/cs_custom_processor/cs_custom_processor.js

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const Redundancy = require('./redundancy')
2525
const { MongoClient } = require('mongodb')
2626
const CustomProcessor = require('./customized_module').CustomProcessor
2727

28+
process.on('uncaughtException', err => Log.log('Uncaught Exception:' + JSON.stringify(err)))
29+
2830
const args = process.argv.slice(2)
2931
let inst = null
3032
if (args.length > 0) inst = parseInt(args[0])

src/demo_simul/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const AppDefs = require('./app-defs')
2424
const LoadConfig = require('./load-config')
2525
const { MongoClient, Double } = require('mongodb')
2626

27+
process.on('uncaughtException', err => Log.log('Uncaught Exception:' + JSON.stringify(err)))
28+
2729
const pipeline = [
2830
{
2931
$project: { documentKey: false },

src/grafana_alert2event/grafana_alert2event.js

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ const app = express()
4646
app.use(express.json())
4747
let soeQueue = new Queue() // queue of SOE events
4848

49+
process.on('uncaughtException', err => console.log('Uncaught Exception:' + JSON.stringify(err)))
50+
4951
app.listen(HTTP_PORT, IP_BIND, () => {
5052
console.log('listening on ' + IP_BIND + ':' + HTTP_PORT)
5153
})

src/mongofw/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const Redundancy = require('./redundancy')
2424
const { MongoClient } = require('mongodb')
2525
const CustomProcessor = require('./customized_module').CustomProcessor
2626

27+
process.on('uncaughtException', err => Log.log('Uncaught Exception:' + JSON.stringify(err)))
28+
2729
const args = process.argv.slice(2)
2830
let inst = null
2931
if (args.length > 0) inst = parseInt(args[0])

src/mongowr/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const Redundancy = require('./redundancy')
2424
const { MongoClient } = require('mongodb')
2525
const CustomProcessor = require('./customized_module').CustomProcessor
2626

27+
process.on('uncaughtException', err => Log.log('Uncaught Exception:' + JSON.stringify(err)))
28+
2729
const args = process.argv.slice(2)
2830
let inst = null
2931
if (args.length > 0) inst = parseInt(args[0])

src/mqtt-sparkplug/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ const AutoTag = require('./auto-tag')
3636
const { castSparkplugValue: castSparkplugValue } = require('./cast')
3737
const autoTag = require('./auto-tag')
3838

39+
process.on('uncaughtException', err => Log.log('Uncaught Exception:' + JSON.stringify(err)))
40+
3941
const SparkplugNS = 'spBv1.0'
4042
const DevicesList = [] // contains either EoN nodes or devices
4143
const ValuesQueue = new Queue() // queue of values to update acquisition

src/server_realtime_auth/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ const dbAuth = require('./app/models')
5858
const { authJwt } = require('./app/middlewares')
5959
const { canSendCommands } = require('./app/middlewares/authJwt.js')
6060

61+
process.on('uncaughtException', err => Log.log('Uncaught Exception:' + JSON.stringify(err)))
62+
6163
// Argument NOAUTH disables user authentication
6264
var args = process.argv.slice(2)
6365
if (args.length > 0) if (args[0] === 'NOAUTH') AUTHENTICATION = false

src/telegraf-listener/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ const serverUdpSocket = dgram.createSocket({ type: 'udp4' })
4141
let bindCount = 0
4242
const grpSep = '~'
4343

44+
process.on('uncaughtException', err => console.log('Uncaught Exception:' + JSON.stringify(err)))
45+
4446
let ListCreatedTags = []
4547
let ValuesQueue = new Queue() // queue of values to update
4648

0 commit comments

Comments
 (0)