remove Bindings::need

a future commit will remove the ability to convert the symbol type used in
bindings to strings. since we only have two users we can inline the error check.
This commit is contained in:
pennae 2022-03-04 19:47:32 +01:00
parent ff0fd91ed2
commit 38de79fcf7
3 changed files with 10 additions and 18 deletions

View file

@ -73,18 +73,6 @@ public:
return nullptr;
}
Attr & need(const Symbol & name, const Pos & pos = noPos)
{
auto a = get(name);
if (!a)
throw Error({
.msg = hintfmt("attribute '%s' missing", name),
.errPos = pos
});
return *a;
}
iterator begin() { return &attrs[0]; }
iterator end() { return &attrs[size_]; }

View file

@ -110,8 +110,10 @@ struct CmdBundle : InstallableCommand
auto outPathS = store->printStorePath(outPath);
if (!outLink) {
auto &attr = vRes->attrs->need(evalState->sName);
outLink = evalState->forceStringNoCtx(*attr.value,*attr.pos);
auto * attr = vRes->attrs->get(evalState->sName);
if (!attr)
throw Error("attribute 'name' missing");
outLink = evalState->forceStringNoCtx(*attr->value, *attr->pos);
}
// TODO: will crash if not a localFSStore?

View file

@ -199,11 +199,13 @@ static int main_nix_prefetch_url(int argc, char * * argv)
state->forceAttrs(v, noPos);
/* Extract the URL. */
auto & attr = v.attrs->need(state->symbols.create("urls"));
state->forceList(*attr.value, noPos);
if (attr.value->listSize() < 1)
auto * attr = v.attrs->get(state->symbols.create("urls"));
if (!attr)
throw Error("attribute 'urls' missing");
state->forceList(*attr->value, noPos);
if (attr->value->listSize() < 1)
throw Error("'urls' list is empty");
url = state->forceString(*attr.value->listElems()[0]);
url = state->forceString(*attr->value->listElems()[0]);
/* Extract the hash mode. */
auto attr2 = v.attrs->get(state->symbols.create("outputHashMode"));