From 52fcf043d7d631b7e350f454cdbd6889ce0e9022 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Wed, 27 May 2026 08:44:28 -0700 Subject: [PATCH] reporter-bugzilla: handle os.getcwd() failure better (#2477455) os.getcwd() can raise FileNotFoundError if the directory went away before it was reached. If -d was passed, this is not a problem and we should survive it. If -d was not passed, we can't continue, but we can at least exit with an informative error. Signed-off-by: Adam Williamson --- src/plugins/python/reporter_bugzilla.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/plugins/python/reporter_bugzilla.py b/src/plugins/python/reporter_bugzilla.py index e6db3bf1..b53ec97a 100755 --- a/src/plugins/python/reporter_bugzilla.py +++ b/src/plugins/python/reporter_bugzilla.py @@ -376,7 +376,11 @@ def log_out(bug_info, rhbz, dump_dir_name): "\n -D, --debug[STR] Debug\n" ) - dump_dir_name = os.getcwd() + try: + dump_dir_name = os.getcwd() + except FileNotFoundError: + # delay handling till after opts are parsed + dump_dir_name = None conf_files = [] fmt_file = os.path.join(const.CONF_DIR, 'plugins/bugzilla_format.conf') fmt_file2 = fmt_file @@ -438,6 +442,14 @@ def log_out(bug_info, rhbz, dump_dir_name): elif opt in ('-D', '--debug'): debug = True + # If os.getcwd didn't work and -d was not set, this will still be + # None and we need to bail now + if not dump_dir_name: + sys.exit( + "Current working directory does not exist and -d not passed, cannot determine " + "dump location" + ) + g_verbose = min(g_verbose, 2) logger_init(logger, ['WARNING', 'INFO', 'DEBUG'][g_verbose])