aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/content-address.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-05-09 14:44:08 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-05-09 14:44:08 -0400
commit6a3a87a714e1f3be1464f8fd4c82714b7d032879 (patch)
tree4a8a911a6f026578e78bc120869451f5bbe95056 /src/libstore/content-address.cc
parente514b3939adb087338a9ef7445afcecb0efb42b1 (diff)
Improve error message for self reference with text hashing
The `ContentAddressWithReferences` method is made total, with error handling now squarely the caller's job. This is better.
Diffstat (limited to 'src/libstore/content-address.cc')
-rw-r--r--src/libstore/content-address.cc32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/libstore/content-address.cc b/src/libstore/content-address.cc
index b62818e11..04f7ac214 100644
--- a/src/libstore/content-address.cc
+++ b/src/libstore/content-address.cc
@@ -232,25 +232,29 @@ ContentAddressWithReferences ContentAddressWithReferences::withoutRefs(const Con
}, ca.raw);
}
-ContentAddressWithReferences ContentAddressWithReferences::fromParts(
- ContentAddressMethod method, Hash hash, StoreReferences refs)
+std::optional<ContentAddressWithReferences> ContentAddressWithReferences::fromPartsOpt(
+ ContentAddressMethod method, Hash hash, StoreReferences refs) noexcept
{
return std::visit(overloaded {
- [&](TextIngestionMethod _) -> ContentAddressWithReferences {
+ [&](TextIngestionMethod _) -> std::optional<ContentAddressWithReferences> {
if (refs.self)
- throw UsageError("Cannot have a self reference with text hashing scheme");
- return TextInfo {
- .hash = { .hash = std::move(hash) },
- .references = std::move(refs.others),
+ return std::nullopt;
+ return ContentAddressWithReferences {
+ TextInfo {
+ .hash = { .hash = std::move(hash) },
+ .references = std::move(refs.others),
+ }
};
},
- [&](FileIngestionMethod m2) -> ContentAddressWithReferences {
- return FixedOutputInfo {
- .hash = {
- .method = m2,
- .hash = std::move(hash),
- },
- .references = std::move(refs),
+ [&](FileIngestionMethod m2) -> std::optional<ContentAddressWithReferences> {
+ return ContentAddressWithReferences {
+ FixedOutputInfo {
+ .hash = {
+ .method = m2,
+ .hash = std::move(hash),
+ },
+ .references = std::move(refs),
+ }
};
},
}, method.raw);