print message with exceptions in a try clause

This commit is contained in:
Ben Burdette 2022-06-02 12:17:28 -06:00
parent 9151dbff88
commit bc0d41e9ba
3 changed files with 22 additions and 6 deletions

View file

@ -464,10 +464,11 @@ EvalState::EvalState(
, emptyBindings(0)
, store(store)
, buildStore(buildStore ? buildStore : store)
, debugRepl(0)
, debugRepl(nullptr)
, debugStop(false)
, debugQuit(false)
, ignoreTry(false)
, trylevel(0)
, regexCache(makeRegexCache())
#if HAVE_BOEHMGC
, valueAllocCache(std::allocate_shared<void *>(traceable_allocator<void *>(), nullptr))
@ -833,7 +834,14 @@ void EvalState::runDebugRepl(const Error * error, const Env & env, const Expr &
: nullptr;
if (error)
printError("%s\n\n" ANSI_BOLD "Starting REPL to allow you to inspect the current state of the evaluator.\n" ANSI_NORMAL, error->what());
{
printError("%s\n\n", error->what());
if (trylevel > 0 && error->info().level != lvlInfo)
printError("This exception occurred in a try clause. use " ANSI_GREEN "--ignore-try" ANSI_NORMAL " to skip these.\n");
printError(ANSI_BOLD "Starting REPL to allow you to inspect the current state of the evaluator.\n" ANSI_NORMAL, error->what());
}
auto se = getStaticEnv(expr);
if (se) {

View file

@ -131,6 +131,7 @@ public:
bool debugStop;
bool debugQuit;
bool ignoreTry;
int trylevel;
std::list<DebugTrace> debugTraces;
std::map<const Expr*, const std::shared_ptr<const StaticEnv>> exprEnvs;
const std::shared_ptr<const StaticEnv> getStaticEnv(const Expr & expr) const

View file

@ -853,11 +853,15 @@ static void prim_tryEval(EvalState & state, const PosIdx pos, Value * * args, Va
auto attrs = state.buildBindings(2);
void (* savedDebugRepl)(ref<EvalState> es, const ValMap & extraEnv) = nullptr;
if (state.debugRepl && state.ignoreTry)
if (state.debugRepl)
{
// to prevent starting the repl from exceptions withing a tryEval, null it.
savedDebugRepl = state.debugRepl;
state.debugRepl = nullptr;
state.trylevel++;
if (state.ignoreTry)
{
// to prevent starting the repl from exceptions withing a tryEval, null it.
savedDebugRepl = state.debugRepl;
state.debugRepl = nullptr;
}
}
try {
@ -873,6 +877,9 @@ static void prim_tryEval(EvalState & state, const PosIdx pos, Value * * args, Va
if (savedDebugRepl)
state.debugRepl = savedDebugRepl;
if (state.debugRepl)
state.trylevel--;
v.mkAttrs(attrs);
}