diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2012-02-23 17:38:08 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-02-23 22:38:51 +0000 |
commit | f588ba69622a2df35417ced184e56c79ac1b40d5 (patch) | |
tree | 57b39e86262b36ef0cd13e06d9a75dde1408fb9c /lib/bb/parse/__init__.py | |
parent | 356c42ed00541dea2c382c57f768a4f431d22db0 (diff) | |
download | bitbake-contrib-f588ba69622a2df35417ced184e56c79ac1b40d5.tar.gz |
bitbake: add file and line number to ParseError
Ensure that a file and line number are reported for ParseError where
possible. This helps particularly in the case of inherit and require
which previously did not report either of these upon failure.
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/bb/parse/__init__.py')
-rw-r--r-- | lib/bb/parse/__init__.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/bb/parse/__init__.py b/lib/bb/parse/__init__.py index c5005aec9..8b7ec73c5 100644 --- a/lib/bb/parse/__init__.py +++ b/lib/bb/parse/__init__.py @@ -37,6 +37,17 @@ logger = logging.getLogger("BitBake.Parsing") class ParseError(Exception): """Exception raised when parsing fails""" + def __init__(self, msg, filename, lineno=0): + self.msg = msg + self.filename = filename + self.lineno = lineno + Exception.__init__(self, msg, filename, lineno) + + def __str__(self): + if self.lineno: + return "ParseError at %s:%d: %s" % (self.filename, self.lineno, self.msg) + else: + return "ParseError in %s: %s" % (self.filename, self.msg) class SkipPackage(Exception): """Exception raised to skip this package""" @@ -78,7 +89,7 @@ def handle(fn, data, include = 0): for h in handlers: if h['supports'](fn, data): return h['handle'](fn, data, include) - raise ParseError("%s is not a BitBake file" % fn) + raise ParseError("not a BitBake file", fn) def init(fn, data): for h in handlers: @@ -111,7 +122,7 @@ def vars_from_file(mypkg, d): parts = myfile[0].split('_') __pkgsplit_cache__[mypkg] = parts if len(parts) > 3: - raise ParseError("Unable to generate default variables from the filename: %s (too many underscores)" % mypkg) + raise ParseError("Unable to generate default variables from filename (too many underscores)", mypkg) exp = 3 - len(parts) tmplist = [] while exp != 0: |