about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-04-08T17·24+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-04-08T17·24+0200
commitdfa2f77d2e1118f32771c2fceefd683435554b9d (patch)
tree36502a51878f50cf01246fdb40e5a5f71d819d75 /src/libstore
parente0a947cde6d11b5182500f024719b04b8997189a (diff)
If a .drv cannot be parsed, show its path
Otherwise you just get ‘expected string `Derive(['’ which isn't very helpful.
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/derivations.cc16
-rw-r--r--src/libstore/derivations.hh4
-rw-r--r--src/libstore/local-store.cc4
-rw-r--r--src/libstore/misc.cc2
4 files changed, 18 insertions, 8 deletions
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;
         }
diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh
index 703410b92552..04b64dfc88a7 100644
--- a/src/libstore/derivations.hh
+++ b/src/libstore/derivations.hh
@@ -59,8 +59,8 @@ class StoreAPI;
 Path writeDerivation(StoreAPI & store,
     const Derivation & drv, const string & name, bool repair = false);
 
-/* Parse a derivation. */
-Derivation parseDerivation(const string & s);
+/* Read a derivation from a file. */
+Derivation readDerivation(const Path & drvPath);
 
 /* Print a derivation. */
 string unparseDerivation(const Derivation & drv);
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 1293a6e8f260..567706d09748 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -661,7 +661,7 @@ unsigned long long LocalStore::addValidPath(const ValidPathInfo & info, bool che
        efficiently query whether a path is an output of some
        derivation. */
     if (isDerivation(info.path)) {
-        Derivation drv = parseDerivation(readFile(info.path));
+        Derivation drv = readDerivation(info.path);
 
         /* Verify that the output paths in the derivation are correct
            (i.e., follow the scheme for computing output paths from
@@ -1290,7 +1290,7 @@ void LocalStore::registerValidPaths(const ValidPathInfos & infos)
             if (isDerivation(i->path)) {
                 // FIXME: inefficient; we already loaded the
                 // derivation in addValidPath().
-                Derivation drv = parseDerivation(readFile(i->path));
+                Derivation drv = readDerivation(i->path);
                 checkDerivationOutputs(i->path, drv);
             }
 
diff --git a/src/libstore/misc.cc b/src/libstore/misc.cc
index 1bf3f9378245..6ecf8787cf61 100644
--- a/src/libstore/misc.cc
+++ b/src/libstore/misc.cc
@@ -11,7 +11,7 @@ Derivation derivationFromPath(StoreAPI & store, const Path & drvPath)
 {
     assertStorePath(drvPath);
     store.ensurePath(drvPath);
-    return parseDerivation(readFile(drvPath));
+    return readDerivation(drvPath);
 }