node-snmp-native icon indicating copy to clipboard operation
node-snmp-native copied to clipboard

Avoid exit on AssertionError

Open leo-combes opened this issue 6 years ago • 3 comments

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?

leo-combes avatar May 21 '18 15:05 leo-combes

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.

bangert avatar May 25 '18 09:05 bangert

I have proposed a PR #71, but seems it have fail :(

leo-combes avatar May 31 '18 01:05 leo-combes

you did not fail! you just need to make sure to change the test as well...

bangert avatar May 31 '18 07:05 bangert