summaryrefslogtreecommitdiff
path: root/menuconfig.py
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-10-30 23:57:16 +0100
committerUlf Magnusson <ulfalizer@gmail.com>2018-10-31 00:02:43 +0100
commit14603c0fed58ebbd137b39b1be2d645d5152716b (patch)
treeee3a8a9c7b0e37647425fdfe032361393afcb055 /menuconfig.py
parentac5ac5f8ada90e3b41b998bd715497be4109b3ab (diff)
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 <errno>] <strerror>"), 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.
Diffstat (limited to 'menuconfig.py')
-rwxr-xr-xmenuconfig.py14
1 files changed, 2 insertions, 12 deletions
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):