1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 10:41:16 +02:00

Make EvalState::getBuiltin safe for missing attr

This commit is contained in:
Robert Hensing 2024-11-19 17:30:58 +01:00
parent 3b76d01f3b
commit a58e38dab7
2 changed files with 10 additions and 1 deletions

View file

@ -525,7 +525,11 @@ Value * EvalState::addPrimOp(PrimOp && primOp)
Value & EvalState::getBuiltin(const std::string & name) 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);
} }

View file

@ -623,6 +623,11 @@ private:
public: 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); Value & getBuiltin(const std::string & name);
struct Doc struct Doc