aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2022-03-31 11:33:16 +0200
committerGitHub <noreply@github.com>2022-03-31 11:33:16 +0200
commit0fe884991416f4a62bc31f69500a62bb8e175403 (patch)
tree22745e9c85cf6bb336fe1477b54b881bdcd815e0 /src
parent28309352d991f50c9d8b54a5a0ee99995a1a5297 (diff)
parent629edd43ba7550be835660fe5df3b65cc4a515c7 (diff)
Merge pull request #6337 from danpls/fix-to-json-repl
libexpr: Throw the correct error in toJSON
Diffstat (limited to 'src')
-rw-r--r--src/libexpr/value-to-json.cc3
-rw-r--r--src/libutil/error.cc3
-rw-r--r--src/libutil/error.hh6
3 files changed, 6 insertions, 6 deletions
diff --git a/src/libexpr/value-to-json.cc b/src/libexpr/value-to-json.cc
index 517da4c01..7b35abca2 100644
--- a/src/libexpr/value-to-json.cc
+++ b/src/libexpr/value-to-json.cc
@@ -84,7 +84,8 @@ void printValueAsJSON(EvalState & state, bool strict,
.msg = hintfmt("cannot convert %1% to JSON", showType(v)),
.errPos = v.determinePos(pos)
});
- throw e.addTrace(pos, hintfmt("message for the trace"));
+ e.addTrace(pos, hintfmt("message for the trace"));
+ throw e;
}
}
diff --git a/src/libutil/error.cc b/src/libutil/error.cc
index b2dfb35b2..02bc5caa5 100644
--- a/src/libutil/error.cc
+++ b/src/libutil/error.cc
@@ -9,10 +9,9 @@ namespace nix {
const std::string nativeSystem = SYSTEM;
-BaseError & BaseError::addTrace(std::optional<ErrPos> e, hintformat hint)
+void BaseError::addTrace(std::optional<ErrPos> e, hintformat hint)
{
err.traces.push_front(Trace { .pos = e, .hint = hint });
- return *this;
}
// c++ std::exception descendants must have a 'const char* what()' function.
diff --git a/src/libutil/error.hh b/src/libutil/error.hh
index 93b789f0b..6a757f9ad 100644
--- a/src/libutil/error.hh
+++ b/src/libutil/error.hh
@@ -175,12 +175,12 @@ public:
const ErrorInfo & info() const { calcWhat(); return err; }
template<typename... Args>
- BaseError & addTrace(std::optional<ErrPos> e, const std::string & fs, const Args & ... args)
+ void addTrace(std::optional<ErrPos> e, const std::string & fs, const Args & ... args)
{
- return addTrace(e, hintfmt(fs, args...));
+ addTrace(e, hintfmt(fs, args...));
}
- BaseError & addTrace(std::optional<ErrPos> e, hintformat hint);
+ void addTrace(std::optional<ErrPos> e, hintformat hint);
bool hasTrace() const { return !err.traces.empty(); }
};