From 8be38f27788239739619db86b6e5270ef7905511 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Thu, 1 Nov 2018 02:48:30 +0100 Subject: Don't show backtraces for expected exceptions in tools KconfigError and IOError are part of normal operation and don't indicate a problem with the library itself. Catch and print them in standard_kconfig() and sys.exit(), to avoid spammy backtraces from e.g. menuconfig.py when Kconfig files don't exist or have errors. --- kconfiglib.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'kconfiglib.py') diff --git a/kconfiglib.py b/kconfiglib.py index 1e320a5..eae271e 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -5585,7 +5585,13 @@ def standard_kconfig(): if len(sys.argv) > 2: sys.exit("usage: {} [Kconfig]".format(sys.argv[0])) - return Kconfig("Kconfig" if len(sys.argv) < 2 else sys.argv[1]) + # Only show backtraces for unexpected exceptions + try: + return Kconfig("Kconfig" if len(sys.argv) < 2 else sys.argv[1]) + except (IOError, KconfigError) as e: + # Some long exception messages have extra newlines for better + # formatting when reported as an unhandled exception. Strip them here. + sys.exit(str(e).strip()) def standard_config_filename(): """ -- cgit v1.2.3