mirror of
https://github.com/NixOS/nix.git
synced 2025-11-30 14:10:59 +01:00
ParsedDerivation: don't take drvPath
It is just use for adding context to errors, but we have `addTrace` to do that. Let the callers do that instead. The callers doing so is a bit duplicated, yes, but this will get better once `DerivationOptions` is included in `Derivation`.
This commit is contained in:
parent
71567373b6
commit
0123640009
6 changed files with 35 additions and 19 deletions
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
ParsedDerivation::ParsedDerivation(const StorePath & drvPath, BasicDerivation & drv)
|
||||
: drvPath(drvPath), drv(drv)
|
||||
ParsedDerivation::ParsedDerivation(BasicDerivation & drv)
|
||||
: drv(drv)
|
||||
{
|
||||
/* Parse the __json attribute, if any. */
|
||||
auto jsonAttr = drv.env.find("__json");
|
||||
|
|
@ -14,7 +14,7 @@ ParsedDerivation::ParsedDerivation(const StorePath & drvPath, BasicDerivation &
|
|||
try {
|
||||
structuredAttrs = std::make_unique<nlohmann::json>(nlohmann::json::parse(jsonAttr->second));
|
||||
} catch (std::exception & e) {
|
||||
throw Error("cannot process __json attribute of '%s': %s", drvPath.to_string(), e.what());
|
||||
throw Error("cannot process __json attribute: %s", e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -29,7 +29,7 @@ std::optional<std::string> ParsedDerivation::getStringAttr(const std::string & n
|
|||
return {};
|
||||
else {
|
||||
if (!i->is_string())
|
||||
throw Error("attribute '%s' of derivation '%s' must be a string", name, drvPath.to_string());
|
||||
throw Error("attribute '%s' of must be a string", name);
|
||||
return i->get<std::string>();
|
||||
}
|
||||
} else {
|
||||
|
|
@ -49,7 +49,7 @@ bool ParsedDerivation::getBoolAttr(const std::string & name, bool def) const
|
|||
return def;
|
||||
else {
|
||||
if (!i->is_boolean())
|
||||
throw Error("attribute '%s' of derivation '%s' must be a Boolean", name, drvPath.to_string());
|
||||
throw Error("attribute '%s' must be a Boolean", name);
|
||||
return i->get<bool>();
|
||||
}
|
||||
} else {
|
||||
|
|
@ -69,11 +69,11 @@ std::optional<Strings> ParsedDerivation::getStringsAttr(const std::string & name
|
|||
return {};
|
||||
else {
|
||||
if (!i->is_array())
|
||||
throw Error("attribute '%s' of derivation '%s' must be a list of strings", name, drvPath.to_string());
|
||||
throw Error("attribute '%s' must be a list of strings", name);
|
||||
Strings res;
|
||||
for (auto j = i->begin(); j != i->end(); ++j) {
|
||||
if (!j->is_string())
|
||||
throw Error("attribute '%s' of derivation '%s' must be a list of strings", name, drvPath.to_string());
|
||||
throw Error("attribute '%s' must be a list of strings", name);
|
||||
res.push_back(j->get<std::string>());
|
||||
}
|
||||
return res;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue