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() ref<EvalState> EvalCommand::getEvalState()
{ {
@ -76,13 +76,14 @@ ref<EvalState> EvalCommand::getEvalState()
#endif #endif
searchPath, getEvalStore(), getStore()); searchPath, getEvalStore(), getStore());
if (startReplOnEvalErrors) if (startReplOnEvalErrors)
debuggerHook = [evalState{ref<EvalState>(evalState)}](const Error & error, const Env & env, const Expr & expr) { 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()); 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) if (expr.staticenv)
{ {
auto vm = mapStaticEnvBindings(*expr.staticenv.get(), env); 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); auto repl = std::make_unique<NixRepl>(evalState);
repl->debugError = debugError; // repl->debugError = debugError;
repl->initEnv(); repl->initEnv();
// tack on a final DebugTrace for the error position. // auto dts = debugError ?
DebugTraceStacker ldts( // std::unique_ptr<DebugTraceStacker>(
*evalState, // // tack on a final DebugTrace for the error position.
DebugTrace // new DebugTraceStacker(
{.pos = debugError->info().errPos, // *evalState,
.expr = expr, // DebugTrace
.env = *repl->env, // {.pos = debugError->info().errPos,
.hint = debugError->info().msg // .expr = expr,
}); // .env = *repl->env,
// .hint = debugError->info().msg
// })
// )
// : nullptr;
// add 'extra' vars. // add 'extra' vars.
std::set<std::string> names; std::set<std::string> names;

View file

@ -36,7 +36,7 @@
namespace nix { 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) 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); auto error = EvalError(s, s2);
if (debuggerHook && expr) if (debuggerHook && expr)
debuggerHook(error, env, *expr); debuggerHook(&error, env, *expr);
throw error; throw error;
} }
@ -768,7 +768,7 @@ LocalNoInlineNoReturn(void throwEvalError(const Pos & pos, const char * s, const
}); });
if (debuggerHook && expr) if (debuggerHook && expr)
debuggerHook(error, env, *expr); debuggerHook(&error, env, *expr);
throw error; throw error;
} }
@ -778,7 +778,7 @@ LocalNoInlineNoReturn(void throwEvalError(const char * s, const string & s2, con
auto error = EvalError(s, s2, s3); auto error = EvalError(s, s2, s3);
if (debuggerHook && expr) if (debuggerHook && expr)
debuggerHook(error, env, *expr); debuggerHook(&error, env, *expr);
throw error; throw error;
} }
@ -791,7 +791,7 @@ LocalNoInlineNoReturn(void throwEvalError(const Pos & pos, const char * s, const
}); });
if (debuggerHook && expr) if (debuggerHook && expr)
debuggerHook(error, env, *expr); debuggerHook(&error, env, *expr);
throw error; throw error;
} }
@ -805,7 +805,7 @@ LocalNoInlineNoReturn(void throwEvalError(const Pos & p1, const char * s, const
}); });
if (debuggerHook && expr) if (debuggerHook && expr)
debuggerHook(error, env, *expr); debuggerHook(&error, env, *expr);
throw error; throw error;
} }
@ -818,7 +818,7 @@ LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, Env &
}); });
if (debuggerHook && expr) if (debuggerHook && expr)
debuggerHook(error, env, *expr); debuggerHook(&error, env, *expr);
throw error; throw error;
} }
@ -831,7 +831,7 @@ LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const
}); });
if (debuggerHook && expr) if (debuggerHook && expr)
debuggerHook(error, env, *expr); debuggerHook(&error, env, *expr);
throw error; throw error;
} }
@ -844,7 +844,7 @@ LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const
}); });
if (debuggerHook && expr) if (debuggerHook && expr)
debuggerHook(error, env, *expr); debuggerHook(&error, env, *expr);
throw error; throw error;
} }
@ -857,7 +857,7 @@ LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const
}); });
if (debuggerHook && expr) if (debuggerHook && expr)
debuggerHook(error, env, *expr); debuggerHook(&error, env, *expr);
throw error; throw error;
} }
@ -870,7 +870,7 @@ LocalNoInlineNoReturn(void throwAssertionError(const Pos & pos, const char * s,
}); });
if (debuggerHook && expr) if (debuggerHook && expr)
debuggerHook(error, env, *expr); debuggerHook(&error, env, *expr);
throw error; throw error;
} }
@ -883,7 +883,7 @@ LocalNoInlineNoReturn(void throwUndefinedVarError(const Pos & pos, const char *
}); });
if (debuggerHook && expr) { if (debuggerHook && expr) {
debuggerHook(error, env, *expr); debuggerHook(&error, env, *expr);
} }
throw error; throw error;
@ -897,7 +897,7 @@ LocalNoInlineNoReturn(void throwMissingArgumentError(const Pos & pos, const char
}); });
if (debuggerHook && expr) if (debuggerHook && expr)
debuggerHook(error, env, *expr); debuggerHook(&error, env, *expr);
throw error; 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) 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); 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 Expr &expr);
void printStaticEnvBindings(const StaticEnv &se, int lvl = 0); void printStaticEnvBindings(const StaticEnv &se, int lvl = 0);
@ -414,14 +414,7 @@ private:
class DebugTraceStacker { class DebugTraceStacker {
public: public:
DebugTraceStacker(EvalState &evalState, DebugTrace t) 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() ~DebugTraceStacker()
{ {
// assert(evalState.debugTraces.front() == trace); // assert(evalState.debugTraces.front() == trace);

View file

@ -18,7 +18,7 @@ MakeError(UndefinedVarError, Error);
MakeError(MissingArgumentError, EvalError); MakeError(MissingArgumentError, EvalError);
MakeError(RestrictedPathError, Error); 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. */ /* Position objects. */