diff options
author | Ben Burdette <bburdette@protonmail.com> | 2022-03-25 18:15:31 -0600 |
---|---|---|
committer | Ben Burdette <bburdette@protonmail.com> | 2022-03-25 18:15:31 -0600 |
commit | 1bec3fb337b86f87e7600fc6b6072ded1a7d4927 (patch) | |
tree | f86e98235d601ee30b6cd80656f35b56681d4898 /src/libcmd/command.cc | |
parent | 88a54108ebcdbeb1432d9afe5363557c25f94cfa (diff) |
add DebugTrace for error
Diffstat (limited to 'src/libcmd/command.cc')
-rw-r--r-- | src/libcmd/command.cc | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 209c455fc..34535802f 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -122,29 +122,45 @@ ref<EvalState> EvalCommand::getEvalState() debuggerHook = [evalState{ref<EvalState>(evalState)}](const Error * error, const Env & env, const Expr & expr) { // clear the screen. // std::cout << "\033[2J\033[1;1H"; - + + auto dts = + error && expr.getPos() ? + std::unique_ptr<DebugTraceStacker>( + new DebugTraceStacker( + *evalState, + DebugTrace + {.pos = *expr.getPos(), + .expr = expr, + .env = env, + .hint = error->info().msg, + .is_error = true + })) + : 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()); - else - { - auto iter = evalState->debugTraces.begin(); - if (iter != evalState->debugTraces.end()) { - std::cout << "\n" << "… " << iter->hint.str() << "\n"; - - if (iter->pos.has_value() && (*iter->pos)) { - auto pos = iter->pos.value(); - std::cout << "\n"; - printAtPos(pos, std::cout); - - auto loc = getCodeLines(pos); - if (loc.has_value()) { - std::cout << "\n"; - printCodeLines(std::cout, "", pos, *loc); - std::cout << "\n"; - } - } - } - } + + // else + // { + // auto iter = evalState->debugTraces.begin(); + // if (iter != evalState->debugTraces.end()) { + // std::cout << "\n" << "… " << iter->hint.str() << "\n"; + + // if (iter->pos.has_value() && (*iter->pos)) { + // auto pos = iter->pos.value(); + // std::cout << "\n"; + // printAtPos(pos, std::cout); + + // auto loc = getCodeLines(pos); + // if (loc.has_value()) { + // std::cout << "\n"; + // printCodeLines(std::cout, "", pos, *loc); + // std::cout << "\n"; + // } + // } + // } + // } if (expr.staticenv) { |