mirror of
https://github.com/NixOS/nix.git
synced 2024-11-25 08:12:29 +00:00
Make EvalState::getBuiltin safe for missing attr
This commit is contained in:
parent
3b76d01f3b
commit
a58e38dab7
@ -525,7 +525,11 @@ Value * EvalState::addPrimOp(PrimOp && primOp)
|
||||
|
||||
Value & EvalState::getBuiltin(const std::string & name)
|
||||
{
|
||||
return *baseEnv.values[0]->attrs()->find(symbols.create(name))->value;
|
||||
auto it = baseEnv.values[0]->attrs()->get(symbols.create(name));
|
||||
if (it)
|
||||
return *it->value;
|
||||
else
|
||||
throw EvalError("builtin '%1%' not found", name);
|
||||
}
|
||||
|
||||
|
||||
|
@ -623,6 +623,11 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Retrieve a specific builtin, equivalent to evaluating `builtins.${name}`.
|
||||
* @param name The attribute name of the builtin to retrieve.
|
||||
* @throws EvalError if the builtin does not exist.
|
||||
*/
|
||||
Value & getBuiltin(const std::string & name);
|
||||
|
||||
struct Doc
|
||||
|
Loading…
Reference in New Issue
Block a user