aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Maudoux <guillaume.maudoux@tweag.io>2022-12-20 12:06:27 +0100
committerGuillaume Maudoux <guillaume.maudoux@tweag.io>2023-01-19 14:12:26 +0100
commit6228b6b9501527ed20da50fe7dc1c28f730c120d (patch)
tree33803ff071a465aae905cda505c21c469b0e34c2 /src
parentca7c5e08c10d3ebd5a491a52c76f29b1dc102375 (diff)
Discuss re-entrant errors and design
Diffstat (limited to 'src')
-rw-r--r--src/libexpr/eval.hh3
-rw-r--r--src/libexpr/tests/error_traces.cc15
2 files changed, 18 insertions, 0 deletions
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index 1d2e5005b..e4d5906bd 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -203,6 +203,9 @@ public:
throw std::move(error);
}
+ // This is dangerous, but gets in line with the idea that error creation and
+ // throwing should not allocate on the stack of hot functions.
+ // as long as errors are immediately thrown, it works.
ErrorBuilder * errorBuilder;
template<typename... Args>
diff --git a/src/libexpr/tests/error_traces.cc b/src/libexpr/tests/error_traces.cc
index 7d6bd2111..5e2213f69 100644
--- a/src/libexpr/tests/error_traces.cc
+++ b/src/libexpr/tests/error_traces.cc
@@ -45,6 +45,21 @@ namespace nix {
);
}
+ TEST_F(ErrorTraceTest, NestedThrows) {
+ try {
+ state.error("Not much").withTrace(noPos, "No more").debugThrow<EvalError>();
+ } catch (BaseError & e) {
+ try {
+ state.error("Not much more").debugThrow<EvalError>();
+ } catch (Error & e2) {
+ e.addTrace(state.positions[noPos], "Something", "");
+ //e2.addTrace(state.positions[noPos], "Something", "");
+ ASSERT_TRUE(e.info().traces.size() == 2);
+ ASSERT_TRUE(e2.info().traces.size() == 0);
+ ASSERT_FALSE(&e.info() == &e2.info());
+ }
+ }
+ }
#define ASSERT_TRACE1(args, type, message) \
ASSERT_THROW( \