diff options
author | Ben Burdette <bburdette@gmail.com> | 2022-01-08 11:03:48 -0700 |
---|---|---|
committer | Ben Burdette <bburdette@gmail.com> | 2022-01-08 11:03:48 -0700 |
commit | a963674d88f2f1af6181f126ed4288ec65b61fc6 (patch) | |
tree | ff9f0c5b4aa339f946181724a2cdfa0bc2d04488 | |
parent | c51b527c280ee08b3ce3ca6d229139c4292b3176 (diff) |
optinoal error; compiles
-rw-r--r-- | src/libcmd/command.cc | 9 | ||||
-rw-r--r-- | src/libcmd/repl.cc | 24 | ||||
-rw-r--r-- | src/libexpr/eval.cc | 33 | ||||
-rw-r--r-- | src/libexpr/eval.hh | 11 | ||||
-rw-r--r-- | src/libexpr/nixexpr.hh | 2 |
5 files changed, 42 insertions, 37 deletions
diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 252bc1fad..ed8f6d295 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -63,7 +63,7 @@ EvalCommand::EvalCommand() }); } -extern std::function<void(const Error & error, const Env & env, const Expr & expr)> debuggerHook; +extern std::function<void(const Error * error, const Env & env, const Expr & expr)> debuggerHook; ref<EvalState> EvalCommand::getEvalState() { @@ -76,13 +76,14 @@ ref<EvalState> EvalCommand::getEvalState() #endif searchPath, getEvalStore(), getStore()); if (startReplOnEvalErrors) - debuggerHook = [evalState{ref<EvalState>(evalState)}](const Error & error, const Env & env, const Expr & expr) { - printError("%s\n\n" ANSI_BOLD "Starting REPL to allow you to inspect the current state of the evaluator.\n" ANSI_NORMAL, error.what()); + debuggerHook = [evalState{ref<EvalState>(evalState)}](const Error * error, const Env & env, const Expr & expr) { + 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()); if (expr.staticenv) { auto vm = mapStaticEnvBindings(*expr.staticenv.get(), env); - runRepl(evalState, &error, expr, *vm); + runRepl(evalState, error, expr, *vm); } }; } diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index fdd63621f..e66cf4430 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -917,19 +917,23 @@ void runRepl( { auto repl = std::make_unique<NixRepl>(evalState); - repl->debugError = debugError; + // repl->debugError = debugError; repl->initEnv(); - // tack on a final DebugTrace for the error position. - DebugTraceStacker ldts( - *evalState, - DebugTrace - {.pos = debugError->info().errPos, - .expr = expr, - .env = *repl->env, - .hint = debugError->info().msg - }); + // auto dts = debugError ? + // std::unique_ptr<DebugTraceStacker>( + // // tack on a final DebugTrace for the error position. + // new DebugTraceStacker( + // *evalState, + // DebugTrace + // {.pos = debugError->info().errPos, + // .expr = expr, + // .env = *repl->env, + // .hint = debugError->info().msg + // }) + // ) + // : nullptr; // add 'extra' vars. std::set<std::string> names; diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index e01147169..7b3745e52 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -36,7 +36,7 @@ namespace nix { -std::function<void(const Error & error, const Env & env, const Expr & expr)> debuggerHook; +std::function<void(const Error * error, const Env & env, const Expr & expr)> debuggerHook; static char * dupString(const char * s) { @@ -756,7 +756,7 @@ LocalNoInlineNoReturn(void throwEvalError(const char * s, const string & s2, Env auto error = EvalError(s, s2); if (debuggerHook && expr) - debuggerHook(error, env, *expr); + debuggerHook(&error, env, *expr); throw error; } @@ -768,7 +768,7 @@ LocalNoInlineNoReturn(void throwEvalError(const Pos & pos, const char * s, const }); if (debuggerHook && expr) - debuggerHook(error, env, *expr); + debuggerHook(&error, env, *expr); throw error; } @@ -778,7 +778,7 @@ LocalNoInlineNoReturn(void throwEvalError(const char * s, const string & s2, con auto error = EvalError(s, s2, s3); if (debuggerHook && expr) - debuggerHook(error, env, *expr); + debuggerHook(&error, env, *expr); throw error; } @@ -791,7 +791,7 @@ LocalNoInlineNoReturn(void throwEvalError(const Pos & pos, const char * s, const }); if (debuggerHook && expr) - debuggerHook(error, env, *expr); + debuggerHook(&error, env, *expr); throw error; } @@ -805,7 +805,7 @@ LocalNoInlineNoReturn(void throwEvalError(const Pos & p1, const char * s, const }); if (debuggerHook && expr) - debuggerHook(error, env, *expr); + debuggerHook(&error, env, *expr); throw error; } @@ -818,7 +818,7 @@ LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, Env & }); if (debuggerHook && expr) - debuggerHook(error, env, *expr); + debuggerHook(&error, env, *expr); throw error; } @@ -831,7 +831,7 @@ LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const }); if (debuggerHook && expr) - debuggerHook(error, env, *expr); + debuggerHook(&error, env, *expr); throw error; } @@ -844,7 +844,7 @@ LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const }); if (debuggerHook && expr) - debuggerHook(error, env, *expr); + debuggerHook(&error, env, *expr); throw error; } @@ -857,7 +857,7 @@ LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const }); if (debuggerHook && expr) - debuggerHook(error, env, *expr); + debuggerHook(&error, env, *expr); throw error; } @@ -870,7 +870,7 @@ LocalNoInlineNoReturn(void throwAssertionError(const Pos & pos, const char * s, }); if (debuggerHook && expr) - debuggerHook(error, env, *expr); + debuggerHook(&error, env, *expr); throw error; } @@ -883,7 +883,7 @@ LocalNoInlineNoReturn(void throwUndefinedVarError(const Pos & pos, const char * }); if (debuggerHook && expr) { - debuggerHook(error, env, *expr); + debuggerHook(&error, env, *expr); } throw error; @@ -897,7 +897,7 @@ LocalNoInlineNoReturn(void throwMissingArgumentError(const Pos & pos, const char }); if (debuggerHook && expr) - debuggerHook(error, env, *expr); + debuggerHook(&error, env, *expr); throw error; } @@ -926,6 +926,13 @@ LocalNoInline(std::unique_ptr<DebugTraceStacker> })); } +DebugTraceStacker::DebugTraceStacker(EvalState &evalState, DebugTrace t) +:evalState(evalState), trace(t) +{ + evalState.debugTraces.push_front(t); + if (debuggerHook) + debuggerHook(0, t.env, t.expr); +} void mkString(Value & v, const char * s) { diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 3c74bb4a1..1a097ab8c 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -24,7 +24,7 @@ enum RepairFlag : bool; typedef void (* PrimOpFun) (EvalState & state, const Pos & pos, Value * * args, Value & v); -extern std::function<void(const Error & error, const Env & env, const Expr & expr)> debuggerHook; +extern std::function<void(const Error * error, const Env & env, const Expr & expr)> debuggerHook; void printStaticEnvBindings(const Expr &expr); void printStaticEnvBindings(const StaticEnv &se, int lvl = 0); @@ -414,14 +414,7 @@ private: class DebugTraceStacker { public: - DebugTraceStacker(EvalState &evalState, DebugTrace t) - :evalState(evalState), trace(t) - { - - // evalState.debuggerHook(const Error & error, const Env & env, const Expr & expr); - - evalState.debugTraces.push_front(t); - } + DebugTraceStacker(EvalState &evalState, DebugTrace t); ~DebugTraceStacker() { // assert(evalState.debugTraces.front() == trace); diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index c4c459f0b..8012c616e 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -18,7 +18,7 @@ MakeError(UndefinedVarError, Error); MakeError(MissingArgumentError, EvalError); MakeError(RestrictedPathError, Error); -extern std::function<void(const Error & error, const Env & env, const Expr & expr)> debuggerHook; +extern std::function<void(const Error * error, const Env & env, const Expr & expr)> debuggerHook; /* Position objects. */ |