node-snmp-native
node-snmp-native copied to clipboard
Avoid exit on AssertionError
I have an a problem with errors caused with malformated packets. We are using autobahn and native-snmp as service or module running on it. In these cases, when an AssertionError is raised, the module exits as if an exception was ocurred, stopping it all.
2018-05-21T12:20:58-0300 [Guest 25380] Woops! An error occurred while parsing an SNMP message. :(
2018-05-21T12:20:58-0300 [Guest 25380] To have this problem corrected, please report the information below verbatim
2018-05-21T12:20:58-0300 [Guest 25380] via email to [email protected] or by creating a GitHub issue at
2018-05-21T12:20:58-0300 [Guest 25380] https://github.com/calmh/node-snmp-native/issues
2018-05-21T12:20:58-0300 [Guest 25380] Thanks!
2018-05-21T12:20:58-0300 [Guest 25380] AssertionError: false == true
2018-05-21T12:20:58-0300 [Guest 25380] at parse (/var/www/project/wampServer/node_modules/snmp-native/lib/snmp.js:236:12)
2018-05-21T12:20:58-0300 [Guest 25380] at EventEmitter.msgReceived (/var/www/project/wampServer/node_modules/snmp-native/lib/snmp.js:416:15)
2018-05-21T12:20:58-0300 [Guest 25380] at emitTwo (events.js:106:13)
2018-05-21T12:20:58-0300 [Guest 25380] at Socket.emit (events.js:191:7)
2018-05-21T12:20:58-0300 [Guest 25380] at UDP.onMessage (dgram.js:549:8)
2018-05-21T12:20:58-0300 [Guest 25380] Message data:
2018-05-21T12:20:58-0300 [Guest 25380] 30 82 00 38 02 01 01 04 81 06 70 75 62 6c 69 63
2018-05-21T12:20:58-0300 [Guest 25380] a2 82 00 28 02 04 28 32 78 01 02 01 00 02 01 00
2018-05-21T12:20:58-0300 [Guest 25380] 30 82 00 18 30 82 00 14 06 82 00 08 2b 06 01 02
2018-05-21T12:20:58-0300 [Guest 25380] 01 01 03 00 43 82 00 04 01 4d ce af
2018-05-21T12:20:58-0300 [Guest 25380] events.js:160
2018-05-21T12:20:58-0300 [Guest 25380] throw er; // Unhandled 'error' event
2018-05-21T12:20:58-0300 [Guest 25380] ^
2018-05-21T12:20:58-0300 [Guest 25380] AssertionError: false == true
2018-05-21T12:20:58-0300 [Guest 25380] at parse (/var/www/project/wampServer/node_modules/snmp-native/lib/snmp.js:236:12)
2018-05-21T12:20:58-0300 [Guest 25380] at EventEmitter.msgReceived (/var/www/project/wampServer/node_modules/snmp-native/lib/snmp.js:416:15)
2018-05-21T12:20:58-0300 [Guest 25380] at emitTwo (events.js:106:13)
2018-05-21T12:20:58-0300 [Guest 25380] at Socket.emit (events.js:191:7)
2018-05-21T12:20:58-0300 [Guest 25380] at UDP.onMessage (dgram.js:549:8)
2018-05-21T12:20:58-0300 [Controller 25341] Guest worker-005 exited with error A process has ended with a probable error condition: process ended with exit code 1.
I could fix it if, instead stop with an AssertionError, the module would continue its execution and only returning an error in the response.
sessionSnmp.get({ oid: getIdOid }, function(error, varbinds){
if(error) { // <--- I would like see the error here
logger.error("error!");
logger.error(error.toString());
result.errorDescription = error.toString();
d.resolve(result);
} else {
try{
result.uptime = varbinds[0].value;
result.error = 'false';
d.resolve(result);
}
catch(e){ // <--- ...or here
logger.error(e);
result.errorDescription = e;
d.resolve(result);
}
}
});
How I could do this?
All assert.xx()
uses are in the parse()
function. You would try to catch the AssertionError in all uses of the parse()
function and return an meaningful error instead. Depending on your specific use case these changes may very well be relevant to others, so feel free to send a PR.
I have proposed a PR #71, but seems it have fail :(
you did not fail! you just need to make sure to change the test as well...