Skip to content

Commit

Permalink
Replace sys.exit with return. (#887)
Browse files Browse the repository at this point in the history
* Replace sys.exit with return, and create an error object for the IOError prior to returning.

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

---------

Co-authored-by: Joe Clarke <[email protected]>
  • Loading branch information
xorrkaz and jclarke-csco authored Jan 24, 2024
1 parent 495dda0 commit e3ff8ab
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pyang/plugins/check_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ def add_opts(self, optparser):
error.add_error_code(
'CHK_UNION_TYPES', 3,
"the member types in the union have changed")
error.add_error_code(
'CHK_IO_ERROR', 1,
"error %s: %s")

def post_validate_ctx(self, ctx, modules):
if not ctx.opts.check_update_from:
Expand Down Expand Up @@ -194,8 +197,9 @@ def check_update(ctx, newmod):
fd = io.open(oldfilename, "r", encoding="utf-8")
text = fd.read()
except IOError as ex:
sys.stderr.write("error %s: %s\n" % (oldfilename, ex))
sys.exit(1)
pos = error.Position(oldfilename)
err_add(ctx.errors, pos, "CHK_IO_ERROR", (oldfilename, ex))
return
if oldfilename in ctx.opts.old_deviation:
oldctx.add_module(oldfilename, text)
else:
Expand Down

0 comments on commit e3ff8ab

Please sign in to comment.