refactor: Unify all exceptions under BaseLibp2pError hierarchy#1197
Open
Abidoyesimze wants to merge 2 commits intolibp2p:mainfrom
Open
refactor: Unify all exceptions under BaseLibp2pError hierarchy#1197Abidoyesimze wants to merge 2 commits intolibp2p:mainfrom
Abidoyesimze wants to merge 2 commits intolibp2p:mainfrom
Conversation
- Enhanced BaseLibp2pError with error_code and context support - Created intermediate base classes: NetworkError, ProtocolError, PeerError, ResourceError, ServiceError, DiscoveryError, PubsubError - Refactored QUIC transport exceptions (24+) to inherit from NetworkError - Refactored Bitswap errors to inherit from ProtocolError - Renamed Bitswap TimeoutError to BitswapTimeoutError to avoid conflict - Refactored Rendezvous discovery errors to inherit from DiscoveryError - Refactored peer-related errors with multiple inheritance for backwards compatibility (PeerStoreError, PeerDataError, InvalidAddrError) - Refactored resource manager exceptions to inherit from ResourceError - Updated existing exceptions (SwarmException, PubsubRouterError) to use intermediate base classes - Added comprehensive tests for exception inheritance - All 12 exception tests passing This implements the unified exception hierarchy as discussed in issue #XXX, allowing users to catch all libp2p errors with BaseLibp2pError while maintaining backwards compatibility where possible. Breaking change: BitswapTimeoutError renamed from TimeoutError
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.
Unify all exceptions under BaseLibp2pError hierarchy
This implements the unified exception hierarchy as discussed in issue #XXX, allowing users to catch all libp2p errors with BaseLibp2pError while maintaining backwards compatibility where possible.
Breaking change: BitswapTimeoutError renamed from TimeoutError
What was wrong?
The codebase had inconsistent exception handling with approximately 50+ exceptions that did not inherit from
BaseLibp2pError. This created several issues:BaseLibp2pError)BaseLibp2pError(network, security, transport, IO)Exception(QUIC, Bitswap, Rendezvous, Resource Manager)KeyErrorandValueError(peer-related errors)BitswapTimeoutErrorconflicted with Python's built-inTimeoutErrorBaseLibp2pErrorlacked support for error codes and contextual informationThis made error handling inconsistent and prevented users from easily catching all libp2p errors in their applications.
How was it fixed?
Approach
Enhanced BaseLibp2pError: Added support for
error_codeandcontextparameters, along with improved__str__and__repr__methods for better debugging.Created Intermediate Base Classes: Introduced 7 logical base classes:
NetworkError- for network-related errors (connections, streams, transport)ProtocolError- for protocol-related errors (negotiation, violations)PeerError- for peer-related errors (peer store, peer data, addresses)ResourceError- for resource management errors (limits, allocation)ServiceError- for service lifecycle errorsDiscoveryError- for discovery-related errors (rendezvous, routing)PubsubError- for pubsub-related errorsRefactored Exceptions Module by Module:
QUICErrorto inherit fromNetworkErrorBitswapErrorto inherit fromProtocolError, renamedTimeoutError→BitswapTimeoutErrorRendezvousErrorto inherit fromDiscoveryErrorKeyError/ValueErrorcompatibility while addingPeerErrorResourceErrorInvalidMACException,CircuitBreakerError, etc.Maintained Backwards Compatibility:
PeerStoreError(PeerError, KeyError)) so code catchingKeyErrorstill worksTimeoutErrorrenameAdded Comprehensive Tests: Created 12 test cases verifying:
BaseLibp2pErrorBaseLibp2pErrorResults
BaseLibp2pErrorBitswapTimeoutErrorrename)Example Usage
To-Do
Cute Animal Picture