about summary refs log tree commit diff
path: root/third_party/nix/src/nix/hash.cc
diff options
context:
space:
mode:
authorKane York <kanepyork@gmail.com>2020-07-28T02·57-0700
committerkanepyork <rikingcoding@gmail.com>2020-08-01T01·15+0000
commit1cbffe21f3284fbad10b4ca27b0d8381bd554ff3 (patch)
tree921c90af406f009a660bb82eb40324a459bca7b7 /third_party/nix/src/nix/hash.cc
parent2a292c71f40f3592e33534ee6d63eb2ca5221d5e (diff)
chore(3p/nix/hash): prefer StatusOr over throwing constructor r/1515
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
Diffstat (limited to '')
-rw-r--r--third_party/nix/src/nix/hash.cc9
1 files changed, 8 insertions, 1 deletions
diff --git a/third_party/nix/src/nix/hash.cc b/third_party/nix/src/nix/hash.cc
index 521f97d53a..24529c67ce 100644
--- a/third_party/nix/src/nix/hash.cc
+++ b/third_party/nix/src/nix/hash.cc
@@ -74,7 +74,14 @@ struct CmdToBase final : Command {
 
   void run() override {
     for (const auto& s : args) {
-      std::cout << fmt("%s\n", Hash(s, ht).to_string(base, base == SRI));
+      auto hash_ = Hash::deserialize(s, ht);
+      if (hash_.ok()) {
+        std::cout << hash_->to_string(base, base == SRI) << "\n";
+      } else {
+        std::cerr << "failed to parse: " << hash_.status().ToString() << "\n";
+        // create a matching blank line, for scripting
+        std::cout << "\n";
+      }
     }
   }
 };