From dfa2f77d2e1118f32771c2fceefd683435554b9d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 8 Apr 2014 19:24:29 +0200 Subject: If a .drv cannot be parsed, show its path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise you just get ‘expected string `Derive(['’ which isn't very helpful. --- src/libstore/derivations.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/libstore/derivations.cc') diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index d91e42784ca5..b452aa2caf56 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -48,7 +48,7 @@ static Path parsePath(std::istream & str) { string s = parseString(str); if (s.size() == 0 || s[0] != '/') - throw Error(format("bad path `%1%' in derivation") % s); + throw FormatError(format("bad path `%1%' in derivation") % s); return s; } @@ -62,7 +62,7 @@ static StringSet parseStrings(std::istream & str, bool arePaths) } -Derivation parseDerivation(const string & s) +static Derivation parseDerivation(const string & s) { Derivation drv; std::istringstream str(s); @@ -112,6 +112,16 @@ Derivation parseDerivation(const string & s) } +Derivation readDerivation(const Path & drvPath) +{ + try { + return parseDerivation(readFile(drvPath)); + } catch (FormatError & e) { + throw Error(format("error parsing derivation `%1%': %2%") % drvPath % e.msg()); + } +} + + static void printString(string & res, const string & s) { res += '"'; @@ -240,7 +250,7 @@ Hash hashDerivationModulo(StoreAPI & store, Derivation drv) Hash h = drvHashes[i->first]; if (h.type == htUnknown) { assert(store.isValidPath(i->first)); - Derivation drv2 = parseDerivation(readFile(i->first)); + Derivation drv2 = readDerivation(i->first); h = hashDerivationModulo(store, drv2); drvHashes[i->first] = h; } -- cgit 1.4.1