-
Notifications
You must be signed in to change notification settings - Fork 91
chore: add documentation for max attempts error #898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KubanjaElijahEldred
wants to merge
2
commits into
hiero-ledger:main
Choose a base branch
from
KubanjaElijahEldred:docs/max-attempts-error-signed
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+411
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| # MaxAttemptsError | ||
|
|
||
| ## Overview | ||
|
|
||
| `MaxAttemptsError` is an exception that occurs when the SDK has exhausted all retry attempts to communicate with a Hedera network node. This error represents transient network issues or node unavailability rather than transaction logic errors. | ||
|
|
||
| ## When It Occurs | ||
|
|
||
| `MaxAttemptsError` is raised when: | ||
| - A node repeatedly fails to respond to requests | ||
| - Network connectivity issues prevent communication with a node | ||
| - The node is temporarily unavailable or overloaded | ||
| - Multiple retry attempts have all failed | ||
|
|
||
| ## Error Attributes | ||
|
|
||
| The `MaxAttemptsError` exception provides the following attributes: | ||
|
|
||
| - **`message`** (str): The error message explaining why the maximum attempts were reached | ||
| - **`node_id`** (str): The ID of the node that was being contacted when the max attempts were reached | ||
| - **`last_error`** (Exception): The last error that occurred during the final attempt | ||
|
|
||
| ## Error Handling Context | ||
|
|
||
| Understanding the different stages of failure is crucial for proper error handling: | ||
|
|
||
| 1. **Precheck Errors** (`PrecheckError`): Failures before transaction submission (e.g., insufficient balance, invalid signature) | ||
| 2. **MaxAttemptsError**: Network/node retry failures during communication | ||
| 3. **Receipt Status Errors** (`ReceiptStatusError`): Failures after consensus (e.g., smart contract revert) | ||
|
|
||
| Many developers assume that if `execute()` doesn't throw, the transaction succeeded. These exceptions explicitly show different stages of failure. | ||
|
|
||
| ## Example Usage | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to demonstrate the other two error types 👍 We can just explain you can catch a MaxAttemptsError like so except MaxAttemptsError as e: Then for a full demonstration, add a link to the example. |
||
|
|
||
| ```python | ||
| from hiero_sdk_python import Client, TransferTransaction | ||
| from hiero_sdk_python.exceptions import MaxAttemptsError, PrecheckError, ReceiptStatusError | ||
|
|
||
| # Create client and transaction | ||
| client = Client.forTestnet() | ||
| transaction = TransferTransaction() | ||
| .addHbarTransfer(sender_account, -1000) | ||
| .addHbarTransfer(receiver_account, 1000) | ||
|
|
||
| try: | ||
| # Execute the transaction | ||
| receipt = transaction.execute(client) | ||
| print("Transaction executed successfully") | ||
|
|
||
| except PrecheckError as e: | ||
| # Handle precheck failures (before submission) | ||
| print(f"Precheck failed: {e.message}") | ||
| print(f"Status: {e.status}") | ||
|
|
||
| except MaxAttemptsError as e: | ||
| # Handle network/node retry failures | ||
| print(f"Max attempts reached on node {e.node_id}: {e.message}") | ||
| if e.last_error: | ||
| print(f"Last error: {e.last_error}") | ||
|
|
||
| # Common recovery strategies: | ||
| # 1. Retry with a different node | ||
| # 2. Wait and retry the same node | ||
| # 3. Check network connectivity | ||
|
|
||
| except ReceiptStatusError as e: | ||
| # Handle post-consensus failures | ||
| print(f"Transaction failed after consensus: {e.message}") | ||
| print(f"Status: {e.status}") | ||
| ``` | ||
|
|
||
| ## Recovery Strategies | ||
|
|
||
| When encountering a `MaxAttemptsError`, consider these approaches: | ||
|
|
||
| ### 1. Retry with Different Node | ||
| ```python | ||
| try: | ||
| receipt = transaction.execute(client) | ||
| except MaxAttemptsError as e: | ||
| # Switch to a different node and retry | ||
| client.setNetwork([{"node2.hedera.com:50211": "0.0.2"}]) | ||
| receipt = transaction.execute(client) | ||
| ``` | ||
|
|
||
| ### 2. Exponential Backoff | ||
| ```python | ||
| import time | ||
|
|
||
| def execute_with_retry(transaction, client, max_retries=3): | ||
| for attempt in range(max_retries): | ||
| try: | ||
| return transaction.execute(client) | ||
| except MaxAttemptsError as e: | ||
| if attempt == max_retries - 1: | ||
| raise | ||
| wait_time = 2 ** attempt # 1, 2, 4 seconds | ||
| time.sleep(wait_time) | ||
| ``` | ||
|
|
||
| ### 3. Node Health Check | ||
| ```python | ||
| try: | ||
| receipt = transaction.execute(client) | ||
| except MaxAttemptsError as e: | ||
| print(f"Node {e.node_id} appears unhealthy") | ||
| # Implement node health monitoring | ||
| # Consider removing the node from rotation temporarily | ||
| ``` | ||
|
|
||
| ## Best Practices | ||
|
|
||
| 1. **Always catch MaxAttemptsError separately** from other exceptions to implement appropriate retry logic | ||
| 2. **Log the node_id** to identify problematic nodes in your network | ||
| 3. **Implement circuit breakers** to temporarily skip consistently failing nodes | ||
| 4. **Use exponential backoff** when retrying to avoid overwhelming the network | ||
| 5. **Monitor last_error** to understand the root cause of failures | ||
|
|
||
| ## Related Documentation | ||
|
|
||
| - [Receipt Status Error](receipt_status_error.md) - Understanding post-consensus failures | ||
| - [Receipts](receipts.md) - Working with transaction receipts | ||
| - [Error Handling Guide](../common_issues.md) - General error handling strategies | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello please move these changelog entries to the UNRELEASED section 👍
i.e. under added roughly in line 10
MaxAttemptsErrorindocs/sdk_developers/training/max_attempts_error.md(2025-11-26)examples/errors/max_attempts_error.pydemonstrating network error handling and recovery strategies (2025-11-26)