Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Avoid exit on AssertionError #70

Open
leo-combes opened this issue May 21, 2018 · 3 comments
Open

Avoid exit on AssertionError #70

leo-combes opened this issue May 21, 2018 · 3 comments

Comments

@leo-combes
Copy link

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?

@bangert
Copy link
Collaborator

bangert commented May 25, 2018

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.

leo-combes added a commit to leo-combes/node-snmp-native that referenced this issue May 31, 2018
When a malformed package is found, an error message is left in the log with the sample of the package that originated it.
There is no exception or cause stop the program.
Is my first PR, so I'm not sure if I are doing this fine.
leo-combes added a commit to leo-combes/node-snmp-native that referenced this issue May 31, 2018
@leo-combes
Copy link
Author

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

@bangert
Copy link
Collaborator

bangert commented May 31, 2018

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

leo-combes added a commit to leo-combes/node-snmp-native that referenced this issue Jun 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants