-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make TypeError
structured
#10199
base: master
Are you sure you want to change the base?
Make TypeError
structured
#10199
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -500,15 +500,15 @@ std::shared_ptr<AttrCursor> AttrCursor::maybeGetAttr(Symbol name, bool forceErro | |||||
// evaluate to see whether 'name' exists | ||||||
} else | ||||||
return nullptr; | ||||||
//error<TypeError>("'%s' is not an attribute set", getAttrPathStr()).debugThrow(); | ||||||
//error<EvalError>("'%s' is not an attribute set", getAttrPathStr()).debugThrow(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Is this better? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I guess There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still, unless we are sure we never catch a |
||||||
} | ||||||
} | ||||||
|
||||||
auto & v = forceValue(); | ||||||
|
||||||
if (v.type() != nAttrs) | ||||||
return nullptr; | ||||||
//error<TypeError>("'%s' is not an attribute set", getAttrPathStr()).debugThrow(); | ||||||
//error<EvalError>("'%s' is not an attribute set", getAttrPathStr()).debugThrow(); | ||||||
Ericson2314 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
auto attr = v.attrs->get(name); | ||||||
|
||||||
|
@@ -574,14 +574,15 @@ std::string AttrCursor::getString() | |||||
debug("using cached string attribute '%s'", getAttrPathStr()); | ||||||
return s->first; | ||||||
} else | ||||||
root->state.error<TypeError>("'%s' is not a string", getAttrPathStr()).debugThrow(); | ||||||
// TODO: Is this an internal error? Where is literally any documentation for the eval cache? | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There probably is no documentation :( From seeing how this is used, I think this cursor thing can either just traverse a regular "uncached" value, or traverse a cache entry's serialized value. The |
||||||
root->state.error<EvalError>("'%s' is not a string", getAttrPathStr()).debugThrow(); | ||||||
} | ||||||
} | ||||||
|
||||||
auto & v = forceValue(); | ||||||
|
||||||
if (v.type() != nString && v.type() != nPath) | ||||||
root->state.error<TypeError>("'%s' is not a string but %s", getAttrPathStr()).debugThrow(); | ||||||
root->state.error<EvalError>("'%s' is not a string but %s", getAttrPathStr()).debugThrow(); | ||||||
|
||||||
return v.type() == nString ? v.c_str() : v.path().to_string(); | ||||||
} | ||||||
|
@@ -616,7 +617,7 @@ string_t AttrCursor::getStringWithContext() | |||||
return *s; | ||||||
} | ||||||
} else | ||||||
root->state.error<TypeError>("'%s' is not a string", getAttrPathStr()).debugThrow(); | ||||||
root->state.error<EvalError>("'%s' is not a string", getAttrPathStr()).debugThrow(); | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -630,7 +631,7 @@ string_t AttrCursor::getStringWithContext() | |||||
else if (v.type() == nPath) | ||||||
return {v.path().to_string(), {}}; | ||||||
else | ||||||
root->state.error<TypeError>("'%s' is not a string but %s", getAttrPathStr()).debugThrow(); | ||||||
root->state.error<EvalError>("'%s' is not a string but %s", getAttrPathStr()).debugThrow(); | ||||||
} | ||||||
|
||||||
bool AttrCursor::getBool() | ||||||
|
@@ -643,14 +644,14 @@ bool AttrCursor::getBool() | |||||
debug("using cached Boolean attribute '%s'", getAttrPathStr()); | ||||||
return *b; | ||||||
} else | ||||||
root->state.error<TypeError>("'%s' is not a Boolean", getAttrPathStr()).debugThrow(); | ||||||
root->state.error<EvalError>("'%s' is not a Boolean", getAttrPathStr()).debugThrow(); | ||||||
} | ||||||
} | ||||||
|
||||||
auto & v = forceValue(); | ||||||
|
||||||
if (v.type() != nBool) | ||||||
root->state.error<TypeError>("'%s' is not a Boolean", getAttrPathStr()).debugThrow(); | ||||||
root->state.error<EvalError>("'%s' is not a Boolean", getAttrPathStr()).debugThrow(); | ||||||
|
||||||
return v.boolean; | ||||||
} | ||||||
|
@@ -665,14 +666,14 @@ NixInt AttrCursor::getInt() | |||||
debug("using cached integer attribute '%s'", getAttrPathStr()); | ||||||
return i->x; | ||||||
} else | ||||||
root->state.error<TypeError>("'%s' is not an integer", getAttrPathStr()).debugThrow(); | ||||||
root->state.error<EvalError>("'%s' is not an integer", getAttrPathStr()).debugThrow(); | ||||||
} | ||||||
} | ||||||
|
||||||
auto & v = forceValue(); | ||||||
|
||||||
if (v.type() != nInt) | ||||||
root->state.error<TypeError>("'%s' is not an integer", getAttrPathStr()).debugThrow(); | ||||||
root->state.error<EvalError>("'%s' is not an integer", getAttrPathStr()).debugThrow(); | ||||||
|
||||||
return v.integer; | ||||||
} | ||||||
|
@@ -687,7 +688,7 @@ std::vector<std::string> AttrCursor::getListOfStrings() | |||||
debug("using cached list of strings attribute '%s'", getAttrPathStr()); | ||||||
return *l; | ||||||
} else | ||||||
root->state.error<TypeError>("'%s' is not a list of strings", getAttrPathStr()).debugThrow(); | ||||||
root->state.error<EvalError>("'%s' is not a list of strings", getAttrPathStr()).debugThrow(); | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -697,7 +698,7 @@ std::vector<std::string> AttrCursor::getListOfStrings() | |||||
root->state.forceValue(v, noPos); | ||||||
|
||||||
if (v.type() != nList) | ||||||
root->state.error<TypeError>("'%s' is not a list", getAttrPathStr()).debugThrow(); | ||||||
root->state.error<EvalError>("'%s' is not a list", getAttrPathStr()).debugThrow(); | ||||||
|
||||||
std::vector<std::string> res; | ||||||
|
||||||
|
@@ -720,14 +721,14 @@ std::vector<Symbol> AttrCursor::getAttrs() | |||||
debug("using cached attrset attribute '%s'", getAttrPathStr()); | ||||||
return *attrs; | ||||||
} else | ||||||
root->state.error<TypeError>("'%s' is not an attribute set", getAttrPathStr()).debugThrow(); | ||||||
root->state.error<EvalError>("'%s' is not an attribute set", getAttrPathStr()).debugThrow(); | ||||||
} | ||||||
} | ||||||
|
||||||
auto & v = forceValue(); | ||||||
|
||||||
if (v.type() != nAttrs) | ||||||
root->state.error<TypeError>("'%s' is not an attribute set", getAttrPathStr()).debugThrow(); | ||||||
root->state.error<EvalError>("'%s' is not an attribute set", getAttrPathStr()).debugThrow(); | ||||||
|
||||||
std::vector<Symbol> attrs; | ||||||
for (auto & attr : *getValue().attrs) | ||||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -4,6 +4,9 @@ | |||
|
||||
#include "error.hh" | ||||
#include "pos-idx.hh" | ||||
#include "print-options.hh" | ||||
#include "print.hh" | ||||
#include "value.hh" | ||||
|
||||
namespace nix { | ||||
|
||||
|
@@ -40,12 +43,39 @@ MakeError(ParseError, Error); | |||
MakeError(AssertionError, EvalError); | ||||
MakeError(ThrownError, AssertionError); | ||||
MakeError(Abort, EvalError); | ||||
MakeError(TypeError, EvalError); | ||||
MakeError(UndefinedVarError, EvalError); | ||||
MakeError(MissingArgumentError, EvalError); | ||||
MakeError(CachedEvalError, EvalError); | ||||
MakeError(InfiniteRecursionError, EvalError); | ||||
|
||||
std::string_view showType(ValueType type, bool article); | ||||
|
||||
Comment on lines
+51
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
It's in |
||||
struct TypeError : public EvalError | ||||
{ | ||||
ValueType expected; | ||||
Value & actual; | ||||
|
||||
TypeError(EvalState & state, ValueType expected, Value & actual) | ||||
: EvalError( | ||||
state, | ||||
"expected %1% but found %2%: %3%", | ||||
showType(expected), | ||||
showType(actual), | ||||
ValuePrinter(state, actual, errorPrintOptions)) | ||||
, expected(expected) | ||||
, actual(actual) | ||||
{ | ||||
} | ||||
}; | ||||
|
||||
struct MissingAttrError : public EvalError | ||||
{ | ||||
Symbol attr; | ||||
Value & actual; | ||||
|
||||
MissingAttrError(EvalState & state, Symbol attr, Value & actual); | ||||
}; | ||||
|
||||
struct InvalidPathError : public EvalError | ||||
{ | ||||
public: | ||||
|
@@ -67,7 +97,7 @@ class EvalErrorBuilder final | |||
friend class EvalState; | ||||
|
||||
template<typename... Args> | ||||
explicit EvalErrorBuilder(EvalState & state, const Args &... args) | ||||
explicit EvalErrorBuilder(EvalState & state, Args && ... args) | ||||
: error(T(state, args...)) | ||||
{ | ||||
} | ||||
|
@@ -83,8 +113,6 @@ public: | |||
|
||||
[[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & withTrace(PosIdx pos, const std::string_view text); | ||||
|
||||
[[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & withFrameTrace(PosIdx pos, const std::string_view text); | ||||
|
||||
Comment on lines
-86
to
-87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated cleanup? |
||||
[[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & withSuggestions(Suggestions & s); | ||||
|
||||
[[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & withFrame(const Env & e, const Expr & ex); | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure? FWIW it came from c1ca4f0