Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace sys.exit with return. #887

Merged
merged 4 commits into from
Jan 24, 2024
Merged

Conversation

xorrkaz
Copy link
Contributor

@xorrkaz xorrkaz commented Jan 22, 2024

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

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
Copy link
Owner

mbj4668 commented Jan 23, 2024

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
Copy link
Contributor Author

xorrkaz commented Jan 23, 2024

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
Copy link
Contributor Author

xorrkaz commented Jan 23, 2024

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'

@mbj4668 mbj4668 merged commit e3ff8ab into mbj4668:master Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants