refactor(hubble): implement Result pattern in OnChainEventStore #2522
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.
Why is this change needed?
The current implementation in OnChainEventStore uses direct error throwing in several critical methods, which breaks the established error handling pattern used throughout the codebase. This inconsistency can lead to:
Unpredictable error propagation
Difficulty in proper error handling by calling code
Potential runtime issues when errors are not properly caught
The codebase predominantly uses the Result pattern from the neverthrow library for error handling. This PR aligns the OnChainEventStore implementation with this pattern by:
Refactoring getActiveSigner to return HubResult
Refactoring _mergeEvent to return HubResult
Improving error handling in _handleSignerEvent
Adding proper error context and recovery in cache operations
Merge Checklist
[x] PR title adheres to the conventional commits standard
[x] PR has a changeset
[x] PR has been tagged with a change label: bugfix
[ ] PR includes documentation (not necessary as this is an internal implementation change)
PR-Codex overview
This PR focuses on enhancing error handling and return types in the
OnChainEventStore
class methods, transitioning from direct returns to usingResultAsync
anderr
for improved error management.Detailed summary
getActiveSigner
to returnHubResult<SignerOnChainEvent>
instead ofPromise<SignerOnChainEvent>
.try-catch
and returningerr
for errors ingetActiveSigner
._mergeEvent
to returnHubResult<number>
and updated error handling to useerr
._mergeEvent
.