[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
33/64: If a .drv cannot be parsed, show its path
From: |
Ludovic Courtès |
Subject: |
33/64: If a .drv cannot be parsed, show its path |
Date: |
Mon, 05 Jan 2015 16:39:01 +0000 |
civodul pushed a commit to branch nix
in repository guix.
commit dfa2f77d2e1118f32771c2fceefd683435554b9d
Author: Eelco Dolstra <address@hidden>
Date: Tue Apr 8 19:24:29 2014 +0200
If a .drv cannot be parsed, show its path
Otherwise you just get ‘expected string `Derive(['’ which isn't very
helpful.
---
src/libexpr/primops.cc | 2 +-
src/libstore/derivations.cc | 16 +++++++++++++---
src/libstore/derivations.hh | 4 ++--
src/libstore/local-store.cc | 4 ++--
src/libstore/misc.cc | 2 +-
src/libutil/util.cc | 2 +-
src/libutil/util.hh | 2 ++
7 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index b4e7564..c69d520 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -67,7 +67,7 @@ static void prim_import(EvalState & state, const Pos & pos,
Value * * args, Valu
}
if (isStorePath(path) && store->isValidPath(path) && isDerivation(path)) {
- Derivation drv = parseDerivation(readFile(path));
+ Derivation drv = readDerivation(path);
Value & w = *state.allocValue();
state.mkAttrs(w, 1 + drv.outputs.size());
mkString(*state.allocAttr(w, state.sDrvPath), path,
singleton<PathSet>("=" + path));
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc
index d91e427..b452aa2 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 703410b..04b64df 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 1293a6e..567706d 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 1bf3f93..6ecf878 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);
}
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 15c462c..846674a 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -1041,7 +1041,7 @@ void expect(std::istream & str, const string & s)
char s2[s.size()];
str.read(s2, s.size());
if (string(s2, s.size()) != s)
- throw Error(format("expected string `%1%'") % s);
+ throw FormatError(format("expected string `%1%'") % s);
}
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 8bedfea..ce2d77c 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -326,6 +326,8 @@ bool hasSuffix(const string & s, const string & suffix);
/* Read string `s' from stream `str'. */
void expect(std::istream & str, const string & s);
+MakeError(FormatError, Error)
+
/* Read a C-style string from stream `str'. */
string parseString(std::istream & str);
- 22/64: derivation: Don't require certain function arguments, (continued)
- 22/64: derivation: Don't require certain function arguments, Ludovic Courtès, 2015/01/05
- 30/64: Update installation instructions, Ludovic Courtès, 2015/01/05
- 23/64: Show position info in string concatenation / addition errors, Ludovic Courtès, 2015/01/05
- 35/64: Don't barf when installing as root, Ludovic Courtès, 2015/01/05
- 31/64: Remove redundant stuff, Ludovic Courtès, 2015/01/05
- 24/64: Show position info in Boolean operations, Ludovic Courtès, 2015/01/05
- 38/64: Fix test evaluation, Ludovic Courtès, 2015/01/05
- 34/64: Add docbook icons to the distribution, Ludovic Courtès, 2015/01/05
- 37/64: Bump date, Ludovic Courtès, 2015/01/05
- 39/64: nix-env: Minor change to '--delete-generations Nd' semantics, Ludovic Courtès, 2015/01/05
- 33/64: If a .drv cannot be parsed, show its path,
Ludovic Courtès <=
- 40/64: trunk -> master, Ludovic Courtès, 2015/01/05
- 17/64: Pass position information to primop calls, Ludovic Courtès, 2015/01/05
- 32/64: Simplify quick start section, Ludovic Courtès, 2015/01/05
- 43/64: Set build-max-jobs to the number of available cores by default, Ludovic Courtès, 2015/01/05
- 41/64: doc fix: swap 'import' and 'export', Ludovic Courtès, 2015/01/05
- 28/64: Ensure that systemd units to into lib, not lib64, Ludovic Courtès, 2015/01/05
- 36/64: Bump version to 1.8, Ludovic Courtès, 2015/01/05
- 44/64: Install an Upstart service, Ludovic Courtès, 2015/01/05
- 45/64: Set up directories and permissions for multi-user install automatically, Ludovic Courtès, 2015/01/05
- 46/64: Simplify multi-user installation instructions, Ludovic Courtès, 2015/01/05