Skip to content

Handle known errors (SubtokenDisabled) #451

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
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bittensor_cli/src/bittensor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,16 @@ def format_error_message(error_message: Union[dict, Exception]) -> str:
else:
err_description = err_docs

matches = {
# A dict of well-known cryptic errors, with better explanations for them.
"SubtokenDisabled": "This subnet is not yet activated. You must wait for it to activate to peform this action."
}

try:
err_description = matches[err_name]
except KeyError:
pass

return f"Subtensor returned `{err_name}({err_type})` error. This means: `{err_description}`."


Expand Down
21 changes: 21 additions & 0 deletions tests/unit_tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest

from bittensor_cli.src.bittensor.utils import format_error_message


@pytest.mark.parametrize(
"err_name,expected_output",
[
(
"SubtokenDisabled",
"This subnet is not yet activated. You must wait for it to activate to peform this action.",
)
],
)
def test_format_error_message_custom_error_message(err_name, expected_output):
error = {"name": err_name, "type": "error type", "docs": "docs"}
formatted_out = format_error_message(error)
assert (
f"Subtensor returned `{err_name}(error type)` error. This means: `{expected_output}`."
== formatted_out
)
Loading