From 1cbffe21f3284fbad10b4ca27b0d8381bd554ff3 Mon Sep 17 00:00:00 2001 From: Kane York Date: Mon, 27 Jul 2020 19:57:04 -0700 Subject: 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 Reviewed-by: tazjin Tested-by: BuildkiteCI --- third_party/nix/src/libexpr/primops.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'third_party/nix/src/libexpr/primops.cc') diff --git a/third_party/nix/src/libexpr/primops.cc b/third_party/nix/src/libexpr/primops.cc index c754f0392b..8e916163b4 100644 --- a/third_party/nix/src/libexpr/primops.cc +++ b/third_party/nix/src/libexpr/primops.cc @@ -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); -- cgit 1.4.1