diff options
author | Alain Zscheile <zseri.devel@ytrizja.de> | 2022-05-04 07:44:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-04 07:44:32 +0200 |
commit | 1385b2007804c8a0370f2a6555045a00e34b07c7 (patch) | |
tree | 3f83e56e03bd60d6c07d0ee14e70949df04b9e0f /src/libstore/remote-store.cc | |
parent | 9489b4b7ef73ab20e8f49213d8711ca56b59107e (diff) |
Get rid of most `.at` calls (#6393)
Use one of `get` or `getOr` instead which will either return a null-pointer (with a nicer error message) or a default value when the key is missing.
Diffstat (limited to 'src/libstore/remote-store.cc')
-rw-r--r-- | src/libstore/remote-store.cc | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 347e32094..14aeba75c 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -853,15 +853,15 @@ std::vector<BuildResult> RemoteStore::buildPathsWithResults( OutputPathMap outputs; auto drv = evalStore->readDerivation(bfd.drvPath); - auto outputHashes = staticOutputHashes(*evalStore, drv); // FIXME: expensive - auto drvOutputs = drv.outputsAndOptPaths(*this); + const auto outputHashes = staticOutputHashes(*evalStore, drv); // FIXME: expensive + const auto drvOutputs = drv.outputsAndOptPaths(*this); for (auto & output : bfd.outputs) { - if (!outputHashes.count(output)) + auto outputHash = get(outputHashes, output); + if (!outputHash) throw Error( "the derivation '%s' doesn't have an output named '%s'", printStorePath(bfd.drvPath), output); - auto outputId = - DrvOutput{outputHashes.at(output), output}; + auto outputId = DrvOutput{ *outputHash, output }; if (settings.isExperimentalFeatureEnabled(Xp::CaDerivations)) { auto realisation = queryRealisation(outputId); @@ -874,13 +874,14 @@ std::vector<BuildResult> RemoteStore::buildPathsWithResults( } else { // If ca-derivations isn't enabled, assume that // the output path is statically known. - assert(drvOutputs.count(output)); - assert(drvOutputs.at(output).second); + const auto drvOutput = get(drvOutputs, output); + assert(drvOutput); + assert(drvOutput->second); res.builtOutputs.emplace( outputId, Realisation { .id = outputId, - .outPath = *drvOutputs.at(output).second + .outPath = *drvOutput->second, }); } } |