mbj4668 / pyang

An extensible YANG validator and converter in python
ISC License
528 stars 342 forks source link

Replace sys.exit with return. #887

Closed xorrkaz closed 5 months ago

xorrkaz commented 5 months ago

If other modules import this code, an exit in a library may have unintended consequences. Like in other places, use return instead of exit.

mbj4668 commented 5 months ago

A simple return is not sufficient, b/c pyang will in this case exit w/ code 0. The proper way is probably to create an error object in ctx.errors, and then return.

xorrkaz commented 5 months ago

Thanks for the comment. That makes sense. The stderr message is also a bit odd when using the plugin as a library. Given we don't have a module yet, I took a stab at a dummy Position and a new error code.

xorrkaz commented 5 months ago

With this code, the result from a standalone run is:

pyang --check-update-from=foo.yang Cisco-IOS-XE-wireless-location-oper.yang
foo.yang:0: error: error foo.yang: [Errno 2] No such file or directory: 'foo.yang'