optinoal error; compiles

This commit is contained in:
Ben Burdette 2022-01-08 11:03:48 -07:00
parent c51b527c28
commit a963674d88
5 changed files with 42 additions and 37 deletions

View file

@ -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);
}
};
}

View file

@ -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;

View file

@ -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)
{

View file

@ -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);

View file

@ -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. */