-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
350 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include "eval-error.hh" | ||
#include "eval.hh" | ||
|
||
namespace nix { | ||
|
||
EvalError & EvalError::atPos(PosIdx pos) | ||
{ | ||
err.errPos = state.positions[pos]; | ||
return *this; | ||
} | ||
|
||
EvalError & EvalError::withTrace(PosIdx pos, const std::string_view text) | ||
{ | ||
err.traces.push_front(Trace{.pos = state.positions[pos], .hint = hintformat(std::string(text)), .frame = false}); | ||
return *this; | ||
} | ||
|
||
EvalError & EvalError::withFrameTrace(PosIdx pos, const std::string_view text) | ||
{ | ||
err.traces.push_front(Trace{.pos = state.positions[pos], .hint = hintformat(std::string(text)), .frame = true}); | ||
return *this; | ||
} | ||
|
||
EvalError & EvalError::withSuggestions(Suggestions & s) | ||
{ | ||
err.suggestions = s; | ||
return *this; | ||
} | ||
|
||
EvalError & EvalError::withFrame(const Env & env, const Expr & expr) | ||
{ | ||
// NOTE: This is abusing side-effects. | ||
// TODO: check compatibility with nested debugger calls. | ||
// TODO: What side-effects?? | ||
state.debugTraces.push_front(DebugTrace{ | ||
.pos = nullptr, | ||
.expr = expr, | ||
.env = env, | ||
.hint = hintformat("Fake frame for debugging purposes"), | ||
.isError = true}); | ||
return *this; | ||
} | ||
|
||
EvalError & EvalError::addTrace(PosIdx pos, hintformat hint, bool frame) | ||
{ | ||
BaseError::addTrace(state.positions[pos], hint, frame); | ||
return *this; | ||
} | ||
|
||
template<typename... Args> | ||
EvalError & EvalError::addTrace(PosIdx pos, std::string_view formatString, const Args &... formatArgs) | ||
{ | ||
|
||
addTrace(state.positions[pos], hintfmt(std::string(formatString), formatArgs...)); | ||
return *this; | ||
} | ||
|
||
void EvalError::debugThrow() | ||
{ | ||
// NOTE: We always use the -LastTrace version as we push the new trace in withFrame() | ||
state.debugThrowLastTrace(this); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#pragma once | ||
|
||
#include "error.hh" | ||
|
||
namespace nix { | ||
|
||
class PosIdx; | ||
struct Env; | ||
struct Expr; | ||
|
||
class EvalState; | ||
|
||
class EvalError : public Error | ||
{ | ||
public: | ||
EvalState & state; | ||
|
||
EvalError(EvalState & state, ErrorInfo && errorInfo) | ||
: Error(errorInfo) | ||
, state(state) | ||
{ | ||
} | ||
|
||
template<typename... Args> | ||
explicit EvalError(EvalState & state, const std::string & formatString, const Args &... formatArgs) | ||
: Error(formatString, formatArgs...) | ||
, state(state) | ||
{ | ||
} | ||
|
||
[[nodiscard, gnu::noinline]] EvalError & atPos(PosIdx pos); | ||
|
||
[[nodiscard, gnu::noinline]] EvalError & withTrace(PosIdx pos, const std::string_view text); | ||
|
||
[[nodiscard, gnu::noinline]] EvalError & withFrameTrace(PosIdx pos, const std::string_view text); | ||
|
||
[[nodiscard, gnu::noinline]] EvalError & withSuggestions(Suggestions & s); | ||
|
||
[[nodiscard, gnu::noinline]] EvalError & withFrame(const Env & e, const Expr & ex); | ||
|
||
[[nodiscard, gnu::noinline]] EvalError & addTrace(PosIdx pos, hintformat hint, bool frame = false); | ||
|
||
template<typename... Args> | ||
EvalError & addTrace(PosIdx pos, std::string_view formatString, const Args &... formatArgs); | ||
|
||
[[gnu::noinline, gnu::noreturn]] void debugThrow(); | ||
}; | ||
|
||
MakeError(ParseError, Error); | ||
MakeError(AssertionError, EvalError); | ||
MakeError(ThrownError, AssertionError); | ||
MakeError(Abort, EvalError); | ||
MakeError(TypeError, EvalError); | ||
MakeError(UndefinedVarError, EvalError); | ||
MakeError(MissingArgumentError, EvalError); | ||
|
||
class InfiniteRecursionError : public EvalError | ||
{ | ||
friend class EvalState; | ||
public: | ||
using EvalError::EvalError; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.