chore(3p/nix/hash): prefer StatusOr over throwing constructor

The use of `unwrap_throw` can be used as a later grep target.

Change-Id: I8c54ed90c4289f07aecb8a1393dd10204c8bce4e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1493
Reviewed-by: glittershark <grfn@gws.fyi>
Reviewed-by: tazjin <mail@tazj.in>
Tested-by: BuildkiteCI
This commit is contained in:
Kane York 2020-07-27 19:57:04 -07:00 committed by kanepyork
parent 2a292c71f4
commit 1cbffe21f3
15 changed files with 97 additions and 49 deletions

View file

@ -704,7 +704,8 @@ static void prim_derivationStrict(EvalState& state, const Pos& pos,
HashType ht =
outputHashAlgo.empty() ? htUnknown : parseHashType(outputHashAlgo);
Hash h(*outputHash, ht);
auto hash_ = Hash::deserialize(*outputHash, ht);
auto h = Hash::unwrap_throw(hash_);
Path outPath =
state.store->makeFixedOutputPath(outputHashRecursive, h, drvName);
@ -1144,9 +1145,10 @@ static void prim_path(EvalState& state, const Pos& pos, Value** args,
} else if (n == "recursive") {
recursive = state.forceBool(*attr.second.value, *attr.second.pos);
} else if (n == "sha256") {
expectedHash =
Hash(state.forceStringNoCtx(*attr.second.value, *attr.second.pos),
htSHA256);
auto hash_ = Hash::deserialize(
state.forceStringNoCtx(*attr.second.value, *attr.second.pos),
htSHA256);
expectedHash = Hash::unwrap_throw(hash_);
} else {
throw EvalError(
format("unsupported argument '%1%' to 'addPath', at %2%") %
@ -2077,9 +2079,10 @@ void fetch(EvalState& state, const Pos& pos, Value** args, Value& v,
request.uri =
state.forceStringNoCtx(*attr.second.value, *attr.second.pos);
} else if (n == "sha256") {
request.expectedHash =
Hash(state.forceStringNoCtx(*attr.second.value, *attr.second.pos),
htSHA256);
auto hash_ = Hash::deserialize(
state.forceStringNoCtx(*attr.second.value, *attr.second.pos),
htSHA256);
request.expectedHash = Hash::unwrap_throw(hash_);
} else if (n == "name") {
request.name =
state.forceStringNoCtx(*attr.second.value, *attr.second.pos);