refactor(utils): centralize error handling in shared utils crate#62
Merged
Conversation
- Create crates/utils/src/errors.rs with CommonError (expanded),
PersonError, ResourceError, GovernanceError — each with From<E> for WasmError
- Remove inline error enum definitions from all three coordinator zomes
- Re-export error types from nondominium_utils::errors in each zome lib.rs
- Fix thiserror version in crates/utils, zome_person, zome_resource to
use workspace = true (v2.0), matching workspace declaration
- Convert 5 .expect() panics to proper error handling:
- 4 link-target conversions in zome_resource changed from .map().expect()
to .filter_map() pattern
- 1 Option unwrap in capability_based_sharing changed to .ok_or()?
Closes #60
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
All three coordinator zomes defined their own error enums inline in
lib.rs, duplicatingthe same infrastructure variants (
SerializationError,EntryOperationFailed,LinkOperationFailed,InvalidInput) across three files. Five.expect()calls in theresource and person zomes would crash the WASM instead of returning proper errors. The
thiserrorversion was pinned at1.0in three places while the workspace declared2.0.This unifies all error types in
crates/utils/src/errors.rsbefore the hREA bridge (Epic#25) multiplies these patterns further.
Changes
Centralized error types:
PersonError,ResourceError, andGovernanceErrorareremoved from each coordinator
lib.rsand defined once incrates/utils/src/errors.rs.Each zome re-exports its error type via
pub use nondominium_utils::errors::XxxErrorsoall existing call sites (
use crate::XxxError) compile without modification.Expanded CommonError: The shared
CommonErrorin utils gains infrastructure variants(
EntryNotFound,RecordNotFound,LinkError,ActionHashNotFound) to cover DHT-levelerror patterns currently handled ad-hoc per zome.
Panic elimination: Five
.expect()calls converted to proper error handling:zome_resourcechanged from.map().expect()to.filter_map()— silently drops unconvertible link targets instead of panickingzome_personcapability sharing changed to.ok_or(PersonError::...)?Version consistency:
thiserrorincrates/utils,zome_person, andzome_resourceCargo.toml changed from pinned
"1.0"to{ workspace = true }(v2.0), matching theworkspace declaration and
zome_gouvernancewhich was already correct.Decisions
XxxError::SerializationError(...)— deferred to a follow-up once call sites stabilize.map()+collect::<Result<Vec<_>>>()?for link-target fixesHow to test
CI runs
bun run build:zomeson every push.Documentation
Updated
documentation/zomes/person_zome.md,resource_zome.md, andgovernance_zome.mdto note that each error type is now defined in
crates/utils/src/errors.rs.Related
SerializationErroretc.) fromdomain enums into
CommonErroronce call sites are stable