From 14603c0fed58ebbd137b39b1be2d645d5152716b Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Tue, 30 Oct 2018 23:57:16 +0100 Subject: Make errno/strerror/filename available on IOError An error reporting flaw was that most raised IOErrors got their errno/strerror/filename fields stripped, due to wanting to show a custom messages. The problem was that adding back 'errno' and 'strerror' made IOError.__str__() always return a fixed string ("[Errno ] "), ignoring any custom message. This is friendly to users, but unfriendly to scripts (the menuconfig had a workaround). Make things friendly to both by raising an internal subclass of IOError instead, that preserves errno/strerror/filename but prints a custom message. The exception can then still be caught as IOError/OSError by scripts. --- menuconfig.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'menuconfig.py') diff --git a/menuconfig.py b/menuconfig.py index 081496f..4aa21c3 100755 --- a/menuconfig.py +++ b/menuconfig.py @@ -1646,22 +1646,12 @@ def _try_load(filename): # filename: # Configuration file to load - # Hack: strerror and errno are lost after we raise the custom IOError with - # troubleshooting help in Kconfig.load_config(). Adding them back to the - # exception loses the custom message. As a workaround, try opening the file - # separately first and report any errors. - try: - open(filename).close() - except OSError as e: - _error("Error loading {}\n\n{} (errno: {})" - .format(filename, e.strerror, errno.errorcode[e.errno])) - return False - try: _kconf.load_config(filename) return True except OSError as e: - _error("Error loading {}\n\nUnknown error".format(filename)) + _error("Error loading {}\n\n{} (errno: {})" + .format(filename, e.strerror, errno.errorcode[e.errno])) return False def _save_dialog(save_fn, default_filename, description): -- cgit v1.2.3