Skip to content

Commit

Permalink
wrap errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nic11 committed Jan 14, 2025
1 parent fef7c63 commit e303367
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 25 deletions.
53 changes: 29 additions & 24 deletions antigo/src/antigo/impl/OnstackContextImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <basic.hpp>
#include <cassert>

#include <cpptrace/basic.hpp>
#include <cpptrace/from_current.hpp>

#include "antigo/Context.h"
#include "antigo/impl/OnstackContextImpl.h"
#include "antigo/impl/ExecutionData.h"
Expand Down Expand Up @@ -45,37 +47,40 @@ OnstackContextImpl::OnstackContextImpl(const char* filename_, size_t linenum_, c
}

OnstackContextImpl::~OnstackContextImpl() {
h.destructing = true;
// 20241220 3 wrap to cpptrace try/catch

if (!(++GetCurrentExecutionData().ticker & 0xffff)) {
GetCurrentExecutionData().orphans.emplace_back(Condense("ticker"));
}
CPPTRACE_TRY {
h.destructing = true;

assert(GetCurrentExecutionData().stackCtxChain.size() && GetCurrentExecutionData().stackCtxChain.back() == this);
if (std::uncaught_exceptions() != h.uncaughtExceptions || (h.downCtx && h.downCtx->h.uncaughtExceptions != h.uncaughtExceptions)) {
auto& w = GetCurrentExecutionData().errorWitnesses;
if (!h.errorOnTop) {
// XXX 20250112 1508 related: условие здесь должно как-то учитывать, что мы могли провалиться сверху с другим слоем эксепшена. или пофиг?)
w.emplace_back(Condense("exception"));
if (!(++GetCurrentExecutionData().ticker & 0xffff)) {
GetCurrentExecutionData().orphans.emplace_back(Condense("ticker"));
}
if (h.downCtx == nullptr) {

assert(GetCurrentExecutionData().stackCtxChain.size() && GetCurrentExecutionData().stackCtxChain.back() == this);
if (std::uncaught_exceptions() != h.uncaughtExceptions || (h.downCtx && h.downCtx->h.uncaughtExceptions != h.uncaughtExceptions)) {
auto& w = GetCurrentExecutionData().errorWitnesses;
if (!h.errorOnTop) {
// XXX 20250112 1508 related: условие здесь должно как-то учитывать, что мы могли провалиться сверху с другим слоем эксепшена. или пофиг?)
w.emplace_back(Condense("exception"));
}
if (h.downCtx == nullptr) {
while (!w.empty()) {
GetCurrentExecutionData().orphans.push_back(std::move(w.back()));
w.pop_back();
}
} else {
h.downCtx->h.errorOnTop = true;
}
} else {
auto& w = GetCurrentExecutionData().errorWitnesses;
while (!w.empty()) {
GetCurrentExecutionData().orphans.push_back(std::move(w.back()));
w.pop_back();
}
} else {
h.downCtx->h.errorOnTop = true;
}
} else {
// TODO 20250102 2359 (after fixing) - maybe it should just use the same functions Has/Pop
auto& w = GetCurrentExecutionData().errorWitnesses;
while (!w.empty()) {
GetCurrentExecutionData().orphans.push_back(std::move(w.back()));
w.pop_back();
}
GetCurrentExecutionData().stackCtxChain.pop_back();
} CPPTRACE_CATCH (const std::exception& e) {
cpptrace::from_current_exception().print();
throw e;
}
GetCurrentExecutionData().stackCtxChain.pop_back();
}

void OnstackContextImpl::CondenseTo(ResolvedContext& to) const {
Expand Down
6 changes: 5 additions & 1 deletion antigo/src/antigo/impl/OnstackContextImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ struct OnstackDataFrame {
};

ResolvedMessageEntry Resolve() const {
return std::visit(ToPreparedVisitor{}, value);
try {
return std::visit(ToPreparedVisitor{}, value);
} catch (const std::exception& e) {
return {"error", "ctx: error while resolving value, variant index " + std::to_string(value.index())};
}
}
};
static_assert(sizeof(OnstackDataFrame) == 16);
Expand Down

0 comments on commit e303367

Please sign in to comment.