summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2019-03-06 03:21:08 +0100
committerUlf Magnusson <ulfalizer@gmail.com>2019-03-06 03:51:04 +0100
commit132e579cb8e4bdd49eb057ea81f5f8528ff80cf9 (patch)
treed1edbc8723115860ab9542d3ab375169eeadeacd
parent66557edc120faac569004ba2bc426c5ac6a1100b (diff)
Give more helpful error messages when files are missing
The current error message talks a lot about $srctree, but $srctree is seldom the culprit in practice. More common is 'source "$(SOME_ENV_VAR)/foo"`, where SOME_ENV_VAR hasn't been set. Include the complete 'source ...' line for missing Kconfig files, and mention unset environment variables as a hint. Only mention $srctree briefly. Also shorten the message when a .config can't be a found a bit. This message would usually only be seen when working directly with the library.
-rw-r--r--kconfiglib.py39
-rw-r--r--testsuite.py6
2 files changed, 19 insertions, 26 deletions
diff --git a/kconfiglib.py b/kconfiglib.py
index aa27967..8c704e7 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -529,7 +529,6 @@ import platform
import re
import subprocess
import sys
-import textwrap
# File layout:
#
@@ -1829,11 +1828,12 @@ class Kconfig(object):
# https://docs.python.org/3/reference/compound_stmts.html#the-try-statement
e = e2
- raise _KconfigIOError(e, "\n" + textwrap.fill(
- "Could not open '{}' ({}: {}){}".format(
- filename, errno.errorcode[e.errno], e.strerror,
- self._srctree_hint()),
- 80))
+ raise _KconfigIOError(e,
+ "Could not open '{}' ({}: {}). Check that the $srctree "
+ "environment variable ({}) is set correctly."
+ .format(filename, errno.errorcode[e.errno], e.strerror,
+ "set to '{}'".format(self.srctree) if self.srctree
+ else "unset or blank"))
def _enter_file(self, full_filename, rel_filename):
# Jumps to the beginning of a sourced Kconfig file, saving the previous
@@ -1873,7 +1873,7 @@ class Kconfig(object):
for name, _ in self._include_path:
if name == rel_filename:
raise KconfigError(
- "\n{}:{}: Recursive 'source' of '{}' detected. Check that "
+ "\n{}:{}: recursive 'source' of '{}' detected. Check that "
"environment variables are set correctly.\n"
"Include path:\n{}"
.format(self._filename, self._linenr, rel_filename,
@@ -2628,11 +2628,15 @@ class Kconfig(object):
sorted(glob.iglob(os.path.join(self.srctree, pattern)))
if not filenames and t0 in _OBL_SOURCE_TOKENS:
- raise KconfigError("\n" + textwrap.fill(
- "{}:{}: '{}' does not exist{}".format(
- self._filename, self._linenr, pattern,
- self._srctree_hint()),
- 80))
+ raise KconfigError(
+ "{}:{}: '{}' not found (in '{}'). Check that "
+ "environment variables are set correctly (e.g. "
+ "$srctree, which is {}). Also note that unset "
+ "environment variables expand to the empty string."
+ .format(self._filename, self._linenr, pattern,
+ self._line.strip(),
+ "set to '{}'".format(self.srctree)
+ if self.srctree else "unset or blank"))
for filename in filenames:
self._enter_file(
@@ -3659,17 +3663,6 @@ class Kconfig(object):
if self._warn_for_redun_assign:
self._warn(msg, filename, linenr)
- def _srctree_hint(self):
- # Hint printed when Kconfig files can't be found or .config files can't
- # be opened
-
- return ". Perhaps the $srctree environment variable ({}) " \
- "is set incorrectly. Note that the current value of $srctree " \
- "is saved when the Kconfig instance is created (for " \
- "consistency and to cleanly separate instances)." \
- .format("set to '{}'".format(self.srctree) if self.srctree
- else "unset or blank")
-
class Symbol(object):
"""
Represents a configuration symbol:
diff --git a/testsuite.py b/testsuite.py
index fbca36c..3301ed5 100644
--- a/testsuite.py
+++ b/testsuite.py
@@ -1059,7 +1059,7 @@ g
Kconfig("tests/Krecursive1")
except KconfigError as e:
verify_equal(str(e), """
-tests/Krecursive2:1: Recursive 'source' of 'tests/Krecursive1' detected. Check that environment variables are set correctly.
+tests/Krecursive2:1: recursive 'source' of 'tests/Krecursive1' detected. Check that environment variables are set correctly.
Include path:
tests/Krecursive1:1
tests/Krecursive2:1
@@ -1076,7 +1076,7 @@ tests/Krecursive2:1
try:
Kconfig("tests/Kmissingsource")
except KconfigError as e:
- if "does not exist" not in str(e):
+ if "not found" not in str(e):
fail("'source' with missing file raised wrong KconfigError")
except:
fail("'source' with missing file raised wrong exception")
@@ -1086,7 +1086,7 @@ tests/Krecursive2:1
try:
Kconfig("tests/Kmissingrsource")
except KconfigError as e:
- if "does not exist" not in str(e):
+ if "not found" not in str(e):
fail("'rsource' with missing file raised wrong KconfigError")
except:
fail("'rsource' with missing file raised wrong exception")