handle exceptions in node processor functions; fixes #2955
Costa Tsaousis (ktsaou) committed
Nov 10, 2017 at 21:45 UTC
ed36f617197a1823bbbb13e4c8842752a27403ec
1 file changed
+12
-4
node.d/node_modules/netdata.js
+12
-4
@@ -68,6 +68,14 @@ var netdata = {
68
modules_configuring: 0,
69
charts: {},
70
71
+ callback_protected: function(callback, param) {
72
+ try {
73
+ return callback(param);
74
+ }
75
+ catch(e) {
76
+ return null;
77
+ }
78
+ },
79
80
processors: {
81
http: {
@@ -90,7 +98,7 @@ var netdata = {
98
if(end === false) {
99
service.error('Got HTTP code ' + response.statusCode + ', failed to get data.');
100
end = true;
93
- return callback(null);
101
+ return netdata.callback_protected(callback, null);
102
}
103
}
104
@@ -102,7 +110,7 @@ var netdata = {
110
if(end === false) {
111
service.error(': Read error, failed to get data.');
112
end = true;
105
- return callback(null);
113
+ return netdata.callback_protected(callback, null);
114
}
115
});
116
@@ -110,7 +118,7 @@ var netdata = {
118
if(end === false) {
119
if(__DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': read completed.');
120
end = true;
113
- return callback(data);
121
+ return netdata.callback_protected(callback, data);
122
}
123
});
124
});
@@ -118,7 +126,7 @@ var netdata = {
126
req.on('error', function(e) {
127
if(__DEBUG === true) netdata.debug('Failed to make request: ' + netdata.stringify(service.request) + ', message: ' + e.message);
128
service.error('Failed to make request, message: ' + e.message);
121
- return callback(null);
129
+ return netdata.callback_protected(callback, null);
130
});
131
132
// write data to request body