aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/labels.yml2
-rw-r--r--doc/manual/src/release-notes/rl-next.md2
-rw-r--r--src/libexpr/value-to-json.cc22
-rw-r--r--src/libstore/local-store.cc21
-rw-r--r--src/libstore/local-store.hh4
-rw-r--r--tests/lang/eval-fail-toJSON.err.exp57
-rw-r--r--tests/lang/eval-fail-toJSON.nix10
7 files changed, 99 insertions, 19 deletions
diff --git a/.github/workflows/labels.yml b/.github/workflows/labels.yml
index 5f949ddc5..d83cb4f18 100644
--- a/.github/workflows/labels.yml
+++ b/.github/workflows/labels.yml
@@ -21,4 +21,4 @@ jobs:
- uses: actions/labeler@v4
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- sync-labels: true
+ sync-labels: false
diff --git a/doc/manual/src/release-notes/rl-next.md b/doc/manual/src/release-notes/rl-next.md
index 065364453..df30ce83d 100644
--- a/doc/manual/src/release-notes/rl-next.md
+++ b/doc/manual/src/release-notes/rl-next.md
@@ -6,3 +6,5 @@
[`builtins.flakeRefToString`](@docroot@/language/builtins.md#builtins-flakeRefToString),
have been added.
These functions are useful for converting between flake references encoded as attribute sets and URLs.
+
+- [`builtins.toJSON`](@docroot@/language/builtins.md#builtins-parseFlakeRef) now prints [--show-trace](@docroot@/command-ref/conf-file.html#conf-show-trace) items for the path in which it finds an evaluation error.
diff --git a/src/libexpr/value-to-json.cc b/src/libexpr/value-to-json.cc
index 4996a5bde..ac3986c87 100644
--- a/src/libexpr/value-to-json.cc
+++ b/src/libexpr/value-to-json.cc
@@ -43,6 +43,7 @@ json printValueAsJSON(EvalState & state, bool strict,
break;
case nNull:
+ // already initialized as null
break;
case nAttrs: {
@@ -59,7 +60,13 @@ json printValueAsJSON(EvalState & state, bool strict,
names.emplace(state.symbols[j.name]);
for (auto & j : names) {
Attr & a(*v.attrs->find(state.symbols.create(j)));
- out[j] = printValueAsJSON(state, strict, *a.value, a.pos, context, copyToStore);
+ try {
+ out[j] = printValueAsJSON(state, strict, *a.value, a.pos, context, copyToStore);
+ } catch (Error & e) {
+ e.addTrace(state.positions[a.pos],
+ hintfmt("while evaluating attribute '%1%'", j));
+ throw;
+ }
}
} else
return printValueAsJSON(state, strict, *i->value, i->pos, context, copyToStore);
@@ -68,8 +75,17 @@ json printValueAsJSON(EvalState & state, bool strict,
case nList: {
out = json::array();
- for (auto elem : v.listItems())
- out.push_back(printValueAsJSON(state, strict, *elem, pos, context, copyToStore));
+ int i = 0;
+ for (auto elem : v.listItems()) {
+ try {
+ out.push_back(printValueAsJSON(state, strict, *elem, pos, context, copyToStore));
+ } catch (Error & e) {
+ e.addTrace({},
+ hintfmt("while evaluating list element at index %1%", i));
+ throw;
+ }
+ i++;
+ }
break;
}
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index f8e0a0ca2..f78bd44ca 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -1506,10 +1506,10 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair)
printInfo("checking path existence...");
StorePathSet validPaths;
- PathSet done;
+ StorePathSet done;
for (auto & i : queryAllValidPaths())
- verifyPath(printStorePath(i), store, done, validPaths, repair, errors);
+ verifyPath(i, store, done, validPaths, repair, errors);
/* Optionally, check the content hashes (slow). */
if (checkContents) {
@@ -1595,19 +1595,12 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair)
}
-void LocalStore::verifyPath(const Path & pathS, const StringSet & store,
- PathSet & done, StorePathSet & validPaths, RepairFlag repair, bool & errors)
+void LocalStore::verifyPath(const StorePath & path, const StringSet & store,
+ StorePathSet & done, StorePathSet & validPaths, RepairFlag repair, bool & errors)
{
checkInterrupt();
- if (!done.insert(pathS).second) return;
-
- if (!isStorePath(pathS)) {
- printError("path '%s' is not in the Nix store", pathS);
- return;
- }
-
- auto path = parseStorePath(pathS);
+ if (!done.insert(path).second) return;
if (!store.count(std::string(path.to_string()))) {
/* Check any referrers first. If we can invalidate them
@@ -1616,11 +1609,13 @@ void LocalStore::verifyPath(const Path & pathS, const StringSet & store,
StorePathSet referrers; queryReferrers(path, referrers);
for (auto & i : referrers)
if (i != path) {
- verifyPath(printStorePath(i), store, done, validPaths, repair, errors);
+ verifyPath(i, store, done, validPaths, repair, errors);
if (validPaths.count(i))
canInvalidate = false;
}
+ auto pathS = printStorePath(path);
+
if (canInvalidate) {
printInfo("path '%s' disappeared, removing from database...", pathS);
auto state(_state.lock());
diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh
index 4125cacf4..c9b570eaa 100644
--- a/src/libstore/local-store.hh
+++ b/src/libstore/local-store.hh
@@ -314,8 +314,8 @@ private:
*/
void invalidatePathChecked(const StorePath & path);
- void verifyPath(const Path & path, const StringSet & store,
- PathSet & done, StorePathSet & validPaths, RepairFlag repair, bool & errors);
+ void verifyPath(const StorePath & path, const StringSet & store,
+ StorePathSet & done, StorePathSet & validPaths, RepairFlag repair, bool & errors);
std::shared_ptr<const ValidPathInfo> queryPathInfoInternal(State & state, const StorePath & path);
diff --git a/tests/lang/eval-fail-toJSON.err.exp b/tests/lang/eval-fail-toJSON.err.exp
new file mode 100644
index 000000000..4e618c203
--- /dev/null
+++ b/tests/lang/eval-fail-toJSON.err.exp
@@ -0,0 +1,57 @@
+error:
+ … while calling the 'toJSON' builtin
+
+ at /pwd/lang/eval-fail-toJSON.nix:1:1:
+
+ 1| builtins.toJSON {
+ | ^
+ 2| a.b = [
+
+ … while evaluating attribute 'a'
+
+ at /pwd/lang/eval-fail-toJSON.nix:2:3:
+
+ 1| builtins.toJSON {
+ 2| a.b = [
+ | ^
+ 3| true
+
+ … while evaluating attribute 'b'
+
+ at /pwd/lang/eval-fail-toJSON.nix:2:3:
+
+ 1| builtins.toJSON {
+ 2| a.b = [
+ | ^
+ 3| true
+
+ … while evaluating list element at index 3
+
+ … while evaluating attribute 'c'
+
+ at /pwd/lang/eval-fail-toJSON.nix:7:7:
+
+ 6| {
+ 7| c.d = throw "hah no";
+ | ^
+ 8| }
+
+ … while evaluating attribute 'd'
+
+ at /pwd/lang/eval-fail-toJSON.nix:7:7:
+
+ 6| {
+ 7| c.d = throw "hah no";
+ | ^
+ 8| }
+
+ … while calling the 'throw' builtin
+
+ at /pwd/lang/eval-fail-toJSON.nix:7:13:
+
+ 6| {
+ 7| c.d = throw "hah no";
+ | ^
+ 8| }
+
+ error: hah no
diff --git a/tests/lang/eval-fail-toJSON.nix b/tests/lang/eval-fail-toJSON.nix
new file mode 100644
index 000000000..8112e1c1f
--- /dev/null
+++ b/tests/lang/eval-fail-toJSON.nix
@@ -0,0 +1,10 @@
+builtins.toJSON {
+ a.b = [
+ true
+ false
+ "it's a bird"
+ {
+ c.d = throw "hah no";
+ }
+ ];
+}