From ebb4a170c024d4bf0d2773b93d916e77a87393d9 Mon Sep 17 00:00:00 2001 From: Elijah Conners Date: Wed, 15 Jun 2022 22:13:31 -0700 Subject: [PATCH] python: remove IOError in certain cases In certain cases, IOError caused the much more general exception OSError to be unreachable. Signed-off-by: Elijah Conners Acked-by: Petr Lautrbach --- python/semanage/semanage | 7 ++----- sandbox/sandbox | 2 -- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/python/semanage/semanage b/python/semanage/semanage index 4e8d64d6..10ab3fa6 100644 --- a/python/semanage/semanage +++ b/python/semanage/semanage @@ -971,8 +971,8 @@ def do_parser(): devnull = os.open(os.devnull, os.O_WRONLY) os.dup2(devnull, sys.stdout.fileno()) sys.exit(1) - except IOError as e: - sys.stderr.write("%s: %s\n" % (e.__class__.__name__, str(e))) + except OSError as e: + sys.stderr.write("%s: %s\n" % (e.__class__.__name__, e.args[1])) sys.exit(1) except KeyboardInterrupt: sys.exit(0) @@ -982,9 +982,6 @@ def do_parser(): except KeyError as e: sys.stderr.write("%s: %s\n" % (e.__class__.__name__, e.args[0])) sys.exit(1) - except OSError as e: - sys.stderr.write("%s: %s\n" % (e.__class__.__name__, e.args[1])) - sys.exit(1) except RuntimeError as e: sys.stderr.write("%s: %s\n" % (e.__class__.__name__, e.args[0])) sys.exit(1) diff --git a/sandbox/sandbox b/sandbox/sandbox index 789621e1..ffac7023 100644 --- a/sandbox/sandbox +++ b/sandbox/sandbox @@ -534,8 +534,6 @@ if __name__ == '__main__': error_exit(error.args[0]) except KeyError as error: error_exit(_("Invalid value %s") % error.args[0]) - except IOError as error: - error_exit(error) except KeyboardInterrupt: rc = 0