diff options
author | Guillaume Maudoux <guillaume.maudoux@tweag.io> | 2022-03-04 05:04:47 +0100 |
---|---|---|
committer | Guillaume Maudoux <guillaume.maudoux@tweag.io> | 2022-03-04 05:04:47 +0100 |
commit | be1f0697468bd6c0f2be4f7e058270c161098e9f (patch) | |
tree | 0a748b160a40d3ac005af29b4b4d322c459f0e84 /src/libexpr/eval-inline.hh | |
parent | 00e242feed5ac848f5948dd2731bfabe603999ce (diff) |
Add error context for most basic coercions
Diffstat (limited to 'src/libexpr/eval-inline.hh')
-rw-r--r-- | src/libexpr/eval-inline.hh | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/libexpr/eval-inline.hh b/src/libexpr/eval-inline.hh index aef1f6351..112c70e7b 100644 --- a/src/libexpr/eval-inline.hh +++ b/src/libexpr/eval-inline.hh @@ -15,10 +15,10 @@ LocalNoInlineNoReturn(void throwEvalError(const Pos & pos, const char * s)) }); } -LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const Value & v)) +LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const Value & v, const std::string & s2)) { throw TypeError({ - .msg = hintfmt(s, showType(v)), + .msg = hintfmt(s, showType(v), s2), .errPos = pos }); } @@ -52,26 +52,26 @@ void EvalState::forceValue(Value & v, Callable getPos) } -inline void EvalState::forceAttrs(Value & v, const Pos & pos) +inline void EvalState::forceAttrs(Value & v, const Pos & pos, const std::string & errorCtx) { - forceAttrs(v, [&]() { return pos; }); + forceAttrs(v, [&]() { return pos; }, errorCtx); } template <typename Callable> -inline void EvalState::forceAttrs(Value & v, Callable getPos) +inline void EvalState::forceAttrs(Value & v, Callable getPos, const std::string & errorCtx) { forceValue(v, getPos); if (v.type() != nAttrs) - throwTypeError(getPos(), "value is %1% while a set was expected", v); + throwTypeError(getPos(), "%2%: value is %1% while a set was expected", v, errorCtx); } -inline void EvalState::forceList(Value & v, const Pos & pos) +inline void EvalState::forceList(Value & v, const Pos & pos, const std::string & errorCtx) { forceValue(v, pos); if (!v.isList()) - throwTypeError(pos, "value is %1% while a list was expected", v); + throwTypeError(pos, "%2%: value is %1% while a list was expected", v, errorCtx); } /* Note: Various places expect the allocated memory to be zeroed. */ |