Discuss re-entrant errors and design

This commit is contained in:
Guillaume Maudoux 2022-12-20 12:06:27 +01:00
parent ca7c5e08c1
commit 6228b6b950
2 changed files with 18 additions and 0 deletions

View file

@ -203,6 +203,9 @@ public:
throw std::move(error); 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; ErrorBuilder * errorBuilder;
template<typename... Args> template<typename... Args>

View file

@ -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) \ #define ASSERT_TRACE1(args, type, message) \
ASSERT_THROW( \ ASSERT_THROW( \