From d47cbf5f544495f47d1cfb8eec0ce11b7a984571 Mon Sep 17 00:00:00 2001 From: leonace924 Date: Fri, 19 Dec 2025 09:25:45 -0500 Subject: [PATCH 1/9] refactor: update the print message utils to be consistent --- bittensor_cli/src/bittensor/utils.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bittensor_cli/src/bittensor/utils.py b/bittensor_cli/src/bittensor/utils.py index c15b8f287..2c9d5204f 100644 --- a/bittensor_cli/src/bittensor/utils.py +++ b/bittensor_cli/src/bittensor/utils.py @@ -130,9 +130,10 @@ def coldkeypub(self): return self._coldkeypub -def print_console(message: str, colour: str, title: str, console_: Console): +def print_console(message: str, colour: str, console_: Console, title: str = ""): + title_part = f"[bold {colour}][{title}]:[/bold {colour}] " if title else "" console_.print( - f"[bold {colour}][{title}]:[/bold {colour}] [{colour}]{message}[/{colour}]\n" + f"{title_part}[{colour}]{message}[/{colour}]\n" ) @@ -140,20 +141,21 @@ def print_verbose(message: str, status=None): """Print verbose messages while temporarily pausing the status spinner.""" if status: status.stop() - print_console(message, "green", "Verbose", verbose_console) + print_console(message, "green", verbose_console, "Verbose") status.start() else: - print_console(message, "green", "Verbose", verbose_console) + print_console(message, "green", verbose_console, "Verbose") def print_error(message: str, status=None): """Print error messages while temporarily pausing the status spinner.""" + error_message = f":cross_mark: {message}" if status: status.stop() - print_console(message, "red", "Error", err_console) + print_console(error_message, "red", err_console) status.start() else: - print_console(message, "red", "Error", err_console) + print_console(error_message, "red", err_console) RAO_PER_TAO = 1e9 From 08a8ac3c8aa6c89d7b35e0112e6b9b60f5486126 Mon Sep 17 00:00:00 2001 From: leonace924 Date: Fri, 19 Dec 2025 09:26:21 -0500 Subject: [PATCH 2/9] fix: update the err_console.print to print_error for wallets --- bittensor_cli/src/commands/wallets.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/bittensor_cli/src/commands/wallets.py b/bittensor_cli/src/commands/wallets.py index fd205237a..575520e3a 100644 --- a/bittensor_cli/src/commands/wallets.py +++ b/bittensor_cli/src/commands/wallets.py @@ -271,7 +271,7 @@ async def regen_hotkey( json_str: Optional[str] = None if json_path: if not os.path.exists(json_path) or not os.path.isfile(json_path): - err_console.print(f"File {json_path} does not exist") + print_error(f"File {json_path} does not exist") return False with open(json_path, "r") as f: json_str = f.read() @@ -605,7 +605,7 @@ async def wallet_balance( elif not all_balances: if not wallet.coldkeypub_file.exists_on_device(): - err_console.print("[bold red]No wallets found.[/bold red]") + print_error("[bold red]No wallets found.[/bold red]") return with console.status("Retrieving balances", spinner="aesthetic") as status: @@ -863,13 +863,13 @@ async def wallet_list( wallets = utils.get_coldkey_wallets_for_path(wallet_path) print_verbose(f"Using wallets path: {wallet_path}") if not wallets: - err_console.print(f"[red]No wallets found in dir: {wallet_path}[/red]") + print_error(f"No wallets found in dir: {wallet_path}") if wallet_name: wallets = [wallet for wallet in wallets if wallet.name == wallet_name] if not wallets: - err_console.print( - f"[red]Wallet '{wallet_name}' not found in dir: {wallet_path}[/red]" + print_error( + f"Wallet '{wallet_name}' not found in dir: {wallet_path}" ) root = Tree("Wallets") @@ -1738,7 +1738,7 @@ async def faucet( max_successes=max_successes, ) if not success: - err_console.print("Faucet run failed.") + print_error("Faucet run failed.") async def swap_hotkey( @@ -1839,7 +1839,7 @@ async def set_id( ) if not success: - err_console.print(f"[red]:cross_mark: Failed![/red] {err_msg}") + print_error(f"Failed! {err_msg}") output_dict["error"] = err_msg if json_output: json_console.print(json.dumps(output_dict)) @@ -1876,7 +1876,7 @@ async def get_id( identity = await subtensor.query_identity(ss58_address) if not identity: - err_console.print( + print_error( f"[blue]Existing identity not found[/blue]" f" for [{COLOR_PALETTE['GENERAL']['COLDKEY']}]{ss58_address}[/{COLOR_PALETTE['GENERAL']['COLDKEY']}]" f" on {subtensor}" @@ -2007,8 +2007,8 @@ async def verify( ) ) else: - err_console.print( - f":cross_mark: Invalid SS58 address or hex public key (64 chars, with or without 0x prefix)- {str(e)}" + print_error( + f"Invalid SS58 address or hex public key (64 chars, with or without 0x prefix)- {str(e)}" ) return False @@ -2025,7 +2025,7 @@ async def verify( ) ) else: - err_console.print(f"[red]:cross_mark: Invalid signature format: {str(e)}") + print_error(f"Invalid signature format: {str(e)}") return False is_valid = keypair.verify(message.encode("utf-8"), signature_bytes) @@ -2041,7 +2041,7 @@ async def verify( console.print("[dark_sea_green3]Signature is valid!\n") console.print(f"[yellow]Signer:[/yellow] {signer_address}") else: - err_console.print(":cross_mark: [red]Signature verification failed!") + print_error("Signature verification failed!") return is_valid From cec8709cddd38be7dbc7bc16b6a5bad4cb0f377b Mon Sep 17 00:00:00 2001 From: leonace924 Date: Fri, 19 Dec 2025 09:39:08 -0500 Subject: [PATCH 3/9] fix: update to print_error in extrinsics files and subtensor interface --- .../src/bittensor/extrinsics/registration.py | 52 +++++++++---------- .../src/bittensor/extrinsics/root.py | 14 ++--- .../src/bittensor/extrinsics/serving.py | 14 ++--- .../src/bittensor/extrinsics/transfer.py | 22 ++++---- .../src/bittensor/subtensor_interface.py | 8 +-- 5 files changed, 55 insertions(+), 55 deletions(-) diff --git a/bittensor_cli/src/bittensor/extrinsics/registration.py b/bittensor_cli/src/bittensor/extrinsics/registration.py index e5bec7a70..ff6831a6e 100644 --- a/bittensor_cli/src/bittensor/extrinsics/registration.py +++ b/bittensor_cli/src/bittensor/extrinsics/registration.py @@ -32,7 +32,7 @@ from bittensor_cli.src.bittensor.utils import ( confirm_action, console, - err_console, + print_error, format_error_message, millify, get_human_readable, @@ -94,7 +94,7 @@ def _get_real_torch(): def log_no_torch_error(): - err_console.print( + print_error( "This command requires torch. You can install torch" " with `pip install torch` and run the command again." ) @@ -509,8 +509,8 @@ async def get_neuron_for_pubkey_and_subnet(): print_verbose("Checking subnet status") if not await subtensor.subnet_exists(netuid): - err_console.print( - f":cross_mark: [red]Failed[/red]: error: [bold white]subnet:{netuid}[/bold white] does not exist." + print_error( + f"Failed: error: [bold white]subnet:{netuid}[/bold white] does not exist." ) return False @@ -587,7 +587,7 @@ async def get_neuron_for_pubkey_and_subnet(): subtensor, netuid=netuid, hotkey_ss58=get_hotkey_pub_ss58(wallet) ) if is_registered: - err_console.print( + print_error( f":white_heavy_check_mark: [dark_sea_green3]Already registered on netuid:{netuid}[/dark_sea_green3]" ) return True @@ -635,8 +635,8 @@ async def get_neuron_for_pubkey_and_subnet(): f"[bold]subnet:{netuid}[/bold][/dark_sea_green3]" ) return True - err_console.print( - f":cross_mark: [red]Failed[/red]: {err_msg}" + print_error( + f"Failed: {err_msg}" ) await asyncio.sleep(0.5) @@ -655,25 +655,25 @@ async def get_neuron_for_pubkey_and_subnet(): return True else: # neuron not found, try again - err_console.print( - ":cross_mark: [red]Unknown error. Neuron not found.[/red]" + print_error( + "Unknown error. Neuron not found." ) continue else: # Exited loop because pow is no longer valid. - err_console.print("[red]POW is stale.[/red]") + print_error("POW is stale.") # Try again. continue if attempts < max_allowed_attempts: # Failed registration, retry pow attempts += 1 - err_console.print( + print_error( ":satellite: Failed registration, retrying pow ...({attempts}/{max_allowed_attempts})" ) else: # Failed to register after max attempts. - err_console.print("[red]No more attempts.[/red]") + print_error("No more attempts.") return False @@ -772,7 +772,7 @@ async def burned_register_extrinsic( ) if not success: - err_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}") + print_error(f"Failed: {err_msg}") await asyncio.sleep(0.5) return False, err_msg, None # Successful registration, final check for neuron and pubkey @@ -808,8 +808,8 @@ async def burned_register_extrinsic( return True, f"Registered on {netuid} with UID {my_uid}", ext_id else: # neuron not found, try again - err_console.print( - ":cross_mark: [red]Unknown error. Neuron not found.[/red]" + print_error( + "Unknown error. Neuron not found." ) return False, "Unknown error. Neuron not found.", ext_id @@ -891,7 +891,7 @@ async def run_faucet_extrinsic( if cuda: if not torch.cuda.is_available(): if prompt: - err_console.print("CUDA is not available.") + print_error("CUDA is not available.") return False, "CUDA is not available." pow_result = await create_pow( subtensor, @@ -936,8 +936,8 @@ async def run_faucet_extrinsic( # process if registration successful, try again if pow is still valid if not await response.is_success: - err_console.print( - f":cross_mark: [red]Failed[/red]: " + print_error( + f"Failed: " f"{format_error_message(await response.error_message)}" ) if attempts == max_allowed_attempts: @@ -1788,13 +1788,13 @@ async def swap_hotkey_extrinsic( ) if netuid is not None and netuid not in netuids_registered: - err_console.print( - f":cross_mark: [red]Failed[/red]: Original hotkey {hk_ss58} is not registered on subnet {netuid}" + print_error( + f"Failed: Original hotkey {hk_ss58} is not registered on subnet {netuid}" ) return False, None elif not len(netuids_registered) > 0: - err_console.print( + print_error( f"Original hotkey [dark_orange]{hk_ss58}[/dark_orange] is not registered on any subnet. " f"Please register and try again" ) @@ -1802,15 +1802,15 @@ async def swap_hotkey_extrinsic( if netuid is not None: if netuid in netuids_registered_new_hotkey: - err_console.print( - f":cross_mark: [red]Failed[/red]: New hotkey {new_hk_ss58} " + print_error( + f"Failed: New hotkey {new_hk_ss58} " f"is already registered on subnet {netuid}" ) return False, None else: if len(netuids_registered_new_hotkey) > 0: - err_console.print( - f":cross_mark: [red]Failed[/red]: New hotkey {new_hk_ss58} " + print_error( + f"Failed: New hotkey {new_hk_ss58} " f"is already registered on subnet(s) {netuids_registered_new_hotkey}" ) return False, None @@ -1864,6 +1864,6 @@ async def swap_hotkey_extrinsic( ) return True, ext_receipt else: - err_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}") + print_error(f"Failed: {err_msg}") time.sleep(0.5) return False, ext_receipt diff --git a/bittensor_cli/src/bittensor/extrinsics/root.py b/bittensor_cli/src/bittensor/extrinsics/root.py index ec75a7cfd..25870e544 100644 --- a/bittensor_cli/src/bittensor/extrinsics/root.py +++ b/bittensor_cli/src/bittensor/extrinsics/root.py @@ -31,7 +31,7 @@ from bittensor_cli.src.bittensor.utils import ( confirm_action, console, - err_console, + print_error, u16_normalized_float, print_verbose, format_error_message, @@ -363,7 +363,7 @@ async def root_register_extrinsic( ) if not success: - err_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}") + print_error(f"Failed: {err_msg}") await asyncio.sleep(0.5) return False, err_msg, None @@ -383,8 +383,8 @@ async def root_register_extrinsic( return True, f"Registered with UID {uid}", ext_id else: # neuron not found, try again - err_console.print( - ":cross_mark: [red]Unknown error. Neuron not found.[/red]" + print_error( + "Unknown error. Neuron not found." ) return False, "Unknown error. Neuron not found.", ext_id @@ -454,7 +454,7 @@ async def _do_set_weights(): ) if my_uid is None: - err_console.print("Your hotkey is not registered to the root network") + print_error("Your hotkey is not registered to the root network") return False if not unlock_key(wallet).success: @@ -546,10 +546,10 @@ async def _do_set_weights(): return True else: fmt_err = format_error_message(error_message) - err_console.print(f":cross_mark: [red]Failed[/red]: {fmt_err}") + print_error(f"Failed: {fmt_err}") return False except SubstrateRequestException as e: fmt_err = format_error_message(e) - err_console.print(":cross_mark: [red]Failed[/red]: error:{}".format(fmt_err)) + print_error("Failed: error:{}".format(fmt_err)) return False diff --git a/bittensor_cli/src/bittensor/extrinsics/serving.py b/bittensor_cli/src/bittensor/extrinsics/serving.py index fb3875bde..3c26b5dbf 100644 --- a/bittensor_cli/src/bittensor/extrinsics/serving.py +++ b/bittensor_cli/src/bittensor/extrinsics/serving.py @@ -10,7 +10,7 @@ from bittensor_cli.src.bittensor.utils import ( confirm_action, console, - err_console, + print_error, format_error_message, unlock_key, print_extrinsic_id, @@ -120,7 +120,7 @@ async def reset_axon_extrinsic( success = await response.is_success if not success: error_msg = format_error_message(await response.error_message) - err_console.print(f":cross_mark: [red]Failed[/red]: {error_msg}") + print_error(f"Failed: {error_msg}") return False, error_msg, None else: ext_id = await response.get_extrinsic_identifier() @@ -132,8 +132,8 @@ async def reset_axon_extrinsic( except Exception as e: error_message = format_error_message(e) - err_console.print( - f":cross_mark: [red]Failed to reset axon: {error_message}[/red]" + print_error( + f"Failed to reset axon: {error_message}" ) return False, error_message, None @@ -240,7 +240,7 @@ async def set_axon_extrinsic( success = await response.is_success if not success: error_msg = format_error_message(await response.error_message) - err_console.print(f":cross_mark: [red]Failed[/red]: {error_msg}") + print_error(f"Failed: {error_msg}") return False, error_msg, None else: ext_id = await response.get_extrinsic_identifier() @@ -252,7 +252,7 @@ async def set_axon_extrinsic( except Exception as e: error_message = format_error_message(e) - err_console.print( - f":cross_mark: [red]Failed to set axon: {error_message}[/red]" + print_error( + f"Failed to set axon: {error_message}" ) return False, error_message, None diff --git a/bittensor_cli/src/bittensor/extrinsics/transfer.py b/bittensor_cli/src/bittensor/extrinsics/transfer.py index 1e2695c0e..5de403466 100644 --- a/bittensor_cli/src/bittensor/extrinsics/transfer.py +++ b/bittensor_cli/src/bittensor/extrinsics/transfer.py @@ -11,7 +11,7 @@ from bittensor_cli.src.bittensor.utils import ( confirm_action, console, - err_console, + print_error, print_verbose, is_valid_bittensor_address_or_public_key, print_error, @@ -95,8 +95,8 @@ async def do_transfer() -> tuple[bool, str, str, Optional[AsyncExtrinsicReceipt] # Validate destination address. if not is_valid_bittensor_address_or_public_key(destination): - err_console.print( - f":cross_mark: [red]Invalid destination SS58 address[/red]:[bold white]\n {destination}[/bold white]" + print_error( + f"Invalid destination SS58 address:[bold white]\n {destination}[/bold white]" ) return False, None console.print(f"[dark_orange]Initiating transfer on network: {subtensor.network}") @@ -139,8 +139,8 @@ async def do_transfer() -> tuple[bool, str, str, Optional[AsyncExtrinsicReceipt] if proxy: if proxy_balance < (amount + existential_deposit) and not allow_death: - err_console.print( - ":cross_mark: [bold red]Not enough balance[/bold red]:\n\n" + print_error( + "[bold red]Not enough balance[/bold red]:\n\n" f" balance: [bright_cyan]{proxy_balance}[/bright_cyan]\n" f" amount: [bright_cyan]{amount}[/bright_cyan]\n" f" would bring you under the existential deposit: [bright_cyan]{existential_deposit}[/bright_cyan].\n" @@ -148,8 +148,8 @@ async def do_transfer() -> tuple[bool, str, str, Optional[AsyncExtrinsicReceipt] ) return False, None if account_balance < fee: - err_console.print( - ":cross_mark: [bold red]Not enough balance[/bold red]:\n\n" + print_error( + "[bold red]Not enough balance[/bold red]:\n\n" f" balance: [bright_cyan]{account_balance}[/bright_cyan]\n" f" fee: [bright_cyan]{fee}[/bright_cyan]\n" f" would bring you under the existential deposit: [bright_cyan]{existential_deposit}[/bright_cyan].\n" @@ -157,15 +157,15 @@ async def do_transfer() -> tuple[bool, str, str, Optional[AsyncExtrinsicReceipt] return False, None if account_balance < amount and allow_death: print_error( - ":cross_mark: [bold red]Not enough balance[/bold red]:\n\n" + "[bold red]Not enough balance[/bold red]:\n\n" f" balance: [bright_red]{account_balance}[/bright_red]\n" f" amount: [bright_red]{amount}[/bright_red]\n" ) return False, None else: if account_balance < (amount + fee + existential_deposit) and not allow_death: - err_console.print( - ":cross_mark: [bold red]Not enough balance[/bold red]:\n\n" + print_error( + "[bold red]Not enough balance[/bold red]:\n\n" f" balance: [bright_cyan]{account_balance}[/bright_cyan]\n" f" amount: [bright_cyan]{amount}[/bright_cyan]\n" f" for fee: [bright_cyan]{fee}[/bright_cyan]\n" @@ -175,7 +175,7 @@ async def do_transfer() -> tuple[bool, str, str, Optional[AsyncExtrinsicReceipt] return False, None elif account_balance < (amount + fee) and allow_death: print_error( - ":cross_mark: [bold red]Not enough balance[/bold red]:\n\n" + "[bold red]Not enough balance[/bold red]:\n\n" f" balance: [bright_red]{account_balance}[/bright_red]\n" f" amount: [bright_red]{amount}[/bright_red]\n" f" for fee: [bright_red]{fee}[/bright_red]" diff --git a/bittensor_cli/src/bittensor/subtensor_interface.py b/bittensor_cli/src/bittensor/subtensor_interface.py index abdcfa961..bf2f91a23 100644 --- a/bittensor_cli/src/bittensor/subtensor_interface.py +++ b/bittensor_cli/src/bittensor/subtensor_interface.py @@ -38,7 +38,7 @@ from bittensor_cli.src.bittensor.utils import ( format_error_message, console, - err_console, + print_error, decode_hex_identity_dict, validate_chain_endpoint, u16_normalized_float, @@ -136,8 +136,8 @@ async def __aenter__(self): await self.substrate.initialize() return self except TimeoutError: # TODO verify - err_console.print( - "\n[red]Error[/red]: Timeout occurred connecting to substrate. " + print_error( + "\nError: Timeout occurred connecting to substrate. " f"Verify your chain and network settings: {self}" ) raise typer.Exit(code=1) @@ -2527,5 +2527,5 @@ async def best_connection(networks: list[str]): t2 = time.monotonic() results[network] = [t2 - t1, latency, t2 - pt1] except Exception as e: - err_console.print(f"Error attempting network {network}: {e}") + print_error(f"Error attempting network {network}: {e}") return results From 5ea66610297c0bc3911cdc52f8472a9fdec26dbb Mon Sep 17 00:00:00 2001 From: leonace924 Date: Fri, 19 Dec 2025 09:58:13 -0500 Subject: [PATCH 4/9] fix: update to print_error in commands folder --- bittensor_cli/src/bittensor/utils.py | 6 +-- bittensor_cli/src/commands/axon/axon.py | 6 +-- .../src/commands/liquidity/liquidity.py | 14 ++--- bittensor_cli/src/commands/proxy.py | 32 +++++------ bittensor_cli/src/commands/stake/add.py | 7 ++- .../src/commands/stake/auto_staking.py | 3 +- .../src/commands/stake/children_hotkeys.py | 30 +++++------ bittensor_cli/src/commands/stake/claim.py | 42 +++++++-------- bittensor_cli/src/commands/sudo.py | 53 +++++++++---------- bittensor_cli/src/commands/weights.py | 10 ++-- 10 files changed, 99 insertions(+), 104 deletions(-) diff --git a/bittensor_cli/src/bittensor/utils.py b/bittensor_cli/src/bittensor/utils.py index 2c9d5204f..8f8b9c943 100644 --- a/bittensor_cli/src/bittensor/utils.py +++ b/bittensor_cli/src/bittensor/utils.py @@ -1500,7 +1500,7 @@ def retry_prompt( if not rejection(var): return var else: - err_console.print(rejection_text) + print_error(rejection_text) def validate_netuid(value: int) -> int: @@ -1816,13 +1816,13 @@ def unlock_key( except PasswordError: err_msg = f"The password used to decrypt your {unlock_type.capitalize()}key Keyfile is invalid." if print_out: - err_console.print(f":cross_mark: [red]{err_msg}[/red]") + print_error(f"Failed: {err_msg}") return unlock_key(wallet, unlock_type, print_out) return UnlockStatus(False, err_msg) except KeyFileError: err_msg = f"{unlock_type.capitalize()}key Keyfile is corrupt, non-writable, or non-readable, or non-existent." if print_out: - err_console.print(f":cross_mark: [red]{err_msg}[/red]") + print_error(f"Failed: {err_msg}") return UnlockStatus(False, err_msg) diff --git a/bittensor_cli/src/commands/axon/axon.py b/bittensor_cli/src/commands/axon/axon.py index 1e351d8c6..ebd7404cd 100644 --- a/bittensor_cli/src/commands/axon/axon.py +++ b/bittensor_cli/src/commands/axon/axon.py @@ -8,7 +8,7 @@ from bittensor_wallet import Wallet from bittensor_cli.src.bittensor.utils import ( - err_console, + print_error, json_console, ) from bittensor_cli.src.bittensor.extrinsics.serving import ( @@ -66,7 +66,7 @@ async def reset( ) ) elif not success: - err_console.print(f"[red]Failed to reset axon: {message}[/red]") + print_error(f"Failed to reset axon: {message}") async def set_axon( @@ -129,4 +129,4 @@ async def set_axon( ) ) elif not success: - err_console.print(f"[red]Failed to set axon: {message}[/red]") + print_error(f"Failed to set axon: {message}") diff --git a/bittensor_cli/src/commands/liquidity/liquidity.py b/bittensor_cli/src/commands/liquidity/liquidity.py index 97ca74fee..7997afc5f 100644 --- a/bittensor_cli/src/commands/liquidity/liquidity.py +++ b/bittensor_cli/src/commands/liquidity/liquidity.py @@ -10,7 +10,7 @@ confirm_action, unlock_key, console, - err_console, + print_error, json_console, print_extrinsic_id, ) @@ -308,7 +308,7 @@ async def add_liquidity( "[green]LiquidityPosition has been successfully added.[/green]" ) else: - err_console.print(f"[red]Error: {message}[/red]") + print_error(f"Error: {message}") return success, message @@ -506,7 +506,7 @@ async def show_liquidity_list( ) return else: - err_console.print(f"Error: {err_msg}") + print_error(f"Error: {err_msg}") return liquidity_table = Table( Column("ID", justify="center"), @@ -588,7 +588,7 @@ async def remove_liquidity( data={"success": False, "err_msg": msg, "positions": positions} ) else: - return err_console.print(f"Error: {msg}") + return print_error(f"Error: {msg}") return None else: position_ids = [p.id for p in positions] @@ -627,7 +627,7 @@ async def remove_liquidity( await print_extrinsic_id(ext_receipt) console.print(f"[green] Position {posid} has been removed.") else: - err_console.print(f"[red] Error removing {posid}: {msg}") + print_error(f"Error removing {posid}: {msg}") else: json_table = {} for (success, msg, ext_receipt), posid in zip(results, position_ids): @@ -659,7 +659,7 @@ async def modify_liquidity( if json_output: json_console.print(json.dumps({"success": False, "err_msg": err_msg})) else: - err_console.print(err_msg) + print_error(err_msg) return False if prompt: @@ -695,5 +695,5 @@ async def modify_liquidity( await print_extrinsic_id(ext_receipt) console.print(f"[green] Position {position_id} has been modified.") else: - err_console.print(f"[red] Error modifying {position_id}: {msg}") + print_error(f"Error modifying {position_id}: {msg}") return success diff --git a/bittensor_cli/src/commands/proxy.py b/bittensor_cli/src/commands/proxy.py index 5438c9c17..0b7835fcd 100644 --- a/bittensor_cli/src/commands/proxy.py +++ b/bittensor_cli/src/commands/proxy.py @@ -11,7 +11,7 @@ print_extrinsic_id, json_console, console, - err_console, + print_error, unlock_key, ProxyAddressBook, is_valid_ss58_address_prompt, @@ -105,7 +105,7 @@ async def submit_proxy( } ) else: - err_console.print(f":cross_mark:[red]Failed: {msg}[/red]") + print_error(f"Failed: {msg}") async def create_proxy( @@ -142,7 +142,7 @@ async def create_proxy( return None if not (ulw := unlock_key(wallet, print_out=not json_output)).success: if not json_output: - err_console.print(ulw.message) + print_error(ulw.message) else: json_console.print_json( data={ @@ -246,7 +246,7 @@ async def create_proxy( } ) else: - err_console.print(f":cross_mark:[red]Failed to create pure proxy: {msg}") + print_error(f"Failed to create pure proxy: {msg}") return None @@ -277,7 +277,7 @@ async def remove_proxy( return None if not (ulw := unlock_key(wallet, print_out=not json_output)).success: if not json_output: - err_console.print(ulw.message) + print_error(ulw.message) else: json_console.print_json( data={ @@ -342,7 +342,7 @@ async def add_proxy( return None if not (ulw := unlock_key(wallet, print_out=not json_output)).success: if not json_output: - err_console.print(ulw.message) + print_error(ulw.message) else: json_console.print_json( data={ @@ -447,7 +447,7 @@ async def add_proxy( } ) else: - err_console.print(f":cross_mark:[red]Failed to add proxy: {msg}") + print_error(f"Failed to add proxy: {msg}") return None @@ -477,11 +477,11 @@ async def kill_proxy( f"To proceed, enter [red]KILL[/red]" ) if confirmation != "KILL": - err_console.print("Invalid input. Exiting.") + print_error("Invalid input. Exiting.") return None if not (ulw := unlock_key(wallet, print_out=not json_output)).success: if not json_output: - err_console.print(ulw.message) + print_error(ulw.message) else: json_console.print_json( data={ @@ -553,8 +553,8 @@ async def execute_announced( if call_hex is None: if not prompt: - err_console.print( - f":cross_mark:[red]You have not provided a call, and are using" + print_error( + f"You have not provided a call, and are using" f" [{COLORS.G.ARG}]--no-prompt[/{COLORS.G.ARG}], so we are unable to request" f"the information to craft this call." ) @@ -589,8 +589,8 @@ async def execute_announced( value = FloatPrompt.ask(f"Enter the amount of Tao for {arg}") value = Balance.from_tao(value) elif "RuntimeCall" in type_name: - err_console.print( - f":cross_mark:[red]Unable to craft a Call Type for arg {arg}. {failure_}" + print_error( + f"Unable to craft a Call Type for arg {arg}. {failure_}" ) return False elif type_name == "NetUid": @@ -608,8 +608,8 @@ async def execute_announced( else: value = False else: - err_console.print( - f":cross_mark:[red]Unrecognized type name {type_name}. {failure_}" + print_error( + f"Unrecognized type name {type_name}. {failure_}" ) return False call_args[arg] = value @@ -661,5 +661,5 @@ async def execute_announced( data={"success": False, "message": msg, "extrinsic_identifier": None} ) else: - err_console.print(f":cross_mark:[red]Failed[/red]. {msg} ") + print_error(f"Failed. {msg} ") return success diff --git a/bittensor_cli/src/commands/stake/add.py b/bittensor_cli/src/commands/stake/add.py index 3c02875b6..18c6578eb 100644 --- a/bittensor_cli/src/commands/stake/add.py +++ b/bittensor_cli/src/commands/stake/add.py @@ -17,7 +17,6 @@ from bittensor_cli.src.bittensor.utils import ( confirm_action, console, - err_console, get_hotkey_wallets_for_wallet, is_valid_ss58_address, print_error, @@ -356,7 +355,7 @@ async def stake_extrinsic( # Check that the subnet exists. subnet_info = all_subnets.get(netuid) if not subnet_info: - err_console.print(f"Subnet with netuid: {netuid} does not exist.") + print_error(f"Subnet with netuid: {netuid} does not exist.") continue current_stake_balances.append(hotkey_stake_map[hotkey[1]][netuid]) @@ -376,8 +375,8 @@ async def stake_extrinsic( # Check enough to stake. if amount_to_stake > remaining_wallet_balance: - err_console.print( - f"[red]Not enough stake[/red]:[bold white]\n wallet balance:{remaining_wallet_balance} < " + print_error( + f"Not enough stake:[bold white]\n wallet balance:{remaining_wallet_balance} < " f"staking amount: {amount_to_stake}[/bold white]" ) return diff --git a/bittensor_cli/src/commands/stake/auto_staking.py b/bittensor_cli/src/commands/stake/auto_staking.py index de45807ee..9fb10847a 100644 --- a/bittensor_cli/src/commands/stake/auto_staking.py +++ b/bittensor_cli/src/commands/stake/auto_staking.py @@ -14,7 +14,6 @@ get_subnet_name, is_valid_ss58_address, print_error, - err_console, unlock_key, print_extrinsic_id, ) @@ -302,5 +301,5 @@ async def set_auto_stake_destination( ) return True - err_console.print(f":cross_mark: [red]Failed[/red]: {error_message}") + print_error(f"Failed: {error_message}") return False diff --git a/bittensor_cli/src/commands/stake/children_hotkeys.py b/bittensor_cli/src/commands/stake/children_hotkeys.py index 2ce72c2c4..f61e1a680 100644 --- a/bittensor_cli/src/commands/stake/children_hotkeys.py +++ b/bittensor_cli/src/commands/stake/children_hotkeys.py @@ -13,7 +13,7 @@ from bittensor_cli.src.bittensor.utils import ( confirm_action, console, - err_console, + print_error, float_to_u16, float_to_u64, u16_to_float, @@ -149,7 +149,7 @@ async def set_children_extrinsic( modifier = "finalized" return True, f"{operation} successfully {modifier}.", ext_id else: - err_console.print(f":cross_mark: [red]Failed[/red]: {error_message}") + print_error(f"Failed: {error_message}") return False, error_message, None @@ -239,7 +239,7 @@ async def set_childkey_take_extrinsic( console.print(":white_heavy_check_mark: [green]Finalized[/green]") return True, f"Successfully {modifier} childkey take", ext_id else: - console.print(f":cross_mark: [red]Failed[/red]: {error_message}") + print_error(f"Failed: {error_message}") return False, error_message, None except SubstrateRequestException as e: @@ -270,7 +270,7 @@ async def get_childkey_take(subtensor, hotkey: str, netuid: int) -> Optional[int return int(childkey_take_) except SubstrateRequestException as e: - err_console.print(f"Error querying ChildKeys: {format_error_message(e)}") + print_error(f"Error querying ChildKeys: {format_error_message(e)}") return None @@ -488,7 +488,7 @@ async def _render_table( if children: netuid_children_tuples.append((netuid_, children)) if not success: - err_console.print( + print_error( f"Failed to get children from subtensor {netuid_}: {err_mg}" ) await _render_table(get_hotkey_pub_ss58(wallet), netuid_children_tuples) @@ -497,7 +497,7 @@ async def _render_table( get_hotkey_pub_ss58(wallet), netuid ) if not success: - err_console.print(f"Failed to get children from subtensor: {err_mg}") + print_error(f"Failed to get children from subtensor: {err_mg}") if children: netuid_children_tuples = [(netuid, children)] await _render_table(get_hotkey_pub_ss58(wallet), netuid_children_tuples) @@ -524,10 +524,10 @@ async def set_children( hotkey = get_hotkey_pub_ss58(wallet) for child in children: if not is_valid_ss58_address(child): - err_console.print(f":cross_mark:[red] Invalid SS58 address: {child}[/red]") + print_error(f"Invalid SS58 address: {child}") return if child == hotkey: - err_console.print(":cross_mark:[red] Cannot set yourself as a child.[/red]") + print_error("Cannot set yourself as a child.") return total_proposed = sum(proportions) @@ -574,7 +574,7 @@ async def set_children( ) else: console.print( - f":cross_mark:[red] Unable to set children hotkeys.[/red] {message}" + f"Unable to set children hotkeys. {message}" ) else: # set children on all subnets that parent is registered on @@ -662,7 +662,7 @@ async def revoke_children( ) else: console.print( - f":cross_mark:[red] Unable to revoke children hotkeys.[/red] {message}" + f"Unable to revoke children hotkeys. {message}" ) else: # revoke children from ALL netuids @@ -701,7 +701,7 @@ async def revoke_children( f"is {current_block}" ) else: - err_console.print( + print_error( f"Childkey revocation failed for netuid {netuid_}: {message}." ) if json_output: @@ -730,8 +730,8 @@ async def childkey_take( def validate_take_value(take_value: float) -> bool: if not (0 <= take_value <= 0.18): - err_console.print( - f":cross_mark:[red] Invalid take value: {take_value}[/red]" + print_error( + f"Invalid take value: {take_value}" ) return False return True @@ -796,8 +796,8 @@ async def set_chk_take_subnet( ) return True, ext_id_ else: - console.print( - f":cross_mark:[red] Unable to set childkey take.[/red] {message}" + print_error( + f"Unable to set childkey take. {message}" ) return False, ext_id_ diff --git a/bittensor_cli/src/commands/stake/claim.py b/bittensor_cli/src/commands/stake/claim.py index b382f083e..ac57681c5 100644 --- a/bittensor_cli/src/commands/stake/claim.py +++ b/bittensor_cli/src/commands/stake/claim.py @@ -14,7 +14,7 @@ from bittensor_cli.src.bittensor.utils import ( confirm_action, console, - err_console, + print_error, unlock_key, print_extrinsic_id, json_console, @@ -84,7 +84,7 @@ async def set_claim_type( ) except ValueError as e: msg = f"Invalid netuid format: {e}" - err_console.print(f"[red]{msg}[/red]") + print_error(msg) if json_output: json_console.print(json.dumps({"success": False, "message": msg})) return False, msg, None @@ -140,7 +140,7 @@ async def set_claim_type( invalid = [n for n in selected_netuids if n not in all_subnets] if invalid: msg = f"Invalid subnets (not available): {group_subnets(invalid)}" - err_console.print(msg) + print_error(msg) if json_output: json_console.print(json.dumps({"success": False, "message": msg})) return False, msg, None @@ -190,7 +190,7 @@ async def set_claim_type( if not (unlock := unlock_key(wallet)).success: msg = f"Failed to unlock wallet: {unlock.message}" - err_console.print(f":cross_mark: [red]{msg}[/red]") + print_error(msg) if json_output: json_console.print(json.dumps({"success": False, "message": msg})) return False, msg, None @@ -224,7 +224,7 @@ async def set_claim_type( return True, msg, ext_id else: msg = f"Failed to set claim type: {err_msg}" - err_console.print(f":cross_mark: [red]{msg}[/red]") + print_error(msg) if json_output: json_console.print(json.dumps({"success": False, "message": msg})) return False, msg, None @@ -365,7 +365,7 @@ async def process_pending_claims( if not (unlock := unlock_key(wallet)).success: msg = f"Failed to unlock wallet: {unlock.message}" - err_console.print(f":cross_mark: [red]{msg}[/red]") + print_error(msg) if json_output: json_console.print( json.dumps( @@ -405,7 +405,7 @@ async def process_pending_claims( return True, msg, ext_id else: msg = f"Failed to claim root emissions: {err_msg}" - err_console.print(f":cross_mark: [red]{msg}[/red]") + print_error(msg) if json_output: json_console.print( json.dumps( @@ -436,27 +436,27 @@ def _prompt_claim_selection(claimable_stake: dict) -> Optional[list[int]]: else: selected = [int(netuid_input.strip())] except ValueError: - err_console.print( - ":cross_mark: [red]Invalid input. Please enter numbers only.[/red]" + print_error( + "Invalid input. Please enter numbers only." ) continue if len(selected) > 5: - err_console.print( - f":cross_mark: [red]You selected {len(selected)} netuids. Maximum is 5. Please try again.[/red]" + print_error( + f"You selected {len(selected)} netuids. Maximum is 5. Please try again." ) continue if len(selected) == 0: - err_console.print( - ":cross_mark: [red]Please select at least one netuid.[/red]" + print_error( + "Please select at least one netuid." ) continue invalid_netuids = [n for n in selected if n not in available_netuids] if invalid_netuids: - err_console.print( - f":cross_mark: [red]Invalid netuids: {', '.join(map(str, invalid_netuids))}[/red]" + print_error( + f"Invalid netuids: {', '.join(map(str, invalid_netuids))}" ) continue @@ -634,17 +634,17 @@ async def _prompt_claim_netuids( ) if not subnet_input.strip(): - err_console.print("[red]No subnets entered. Please try again.[/red]") + print_error("No subnets entered. Please try again.") continue try: selected = parse_subnet_range(subnet_input, total_subnets=len(all_subnets)) invalid = [s for s in selected if s not in all_subnets] if invalid: - err_console.print( - f"[red]Invalid subnets (not available): {group_subnets(invalid)}[/red]" + print_error( + f"Invalid subnets (not available): {group_subnets(invalid)}" ) - err_console.print("[yellow]Please try again.[/yellow]") + print_error("[yellow]Please try again.[/yellow]") continue if mode == "keep": @@ -670,8 +670,8 @@ async def _prompt_claim_netuids( ) except ValueError as e: - err_console.print( - f"Invalid subnet selection: {e}\n[yellow]Please try again." + print_error( + f"Invalid subnet selection: {e}\nPlease try again." ) diff --git a/bittensor_cli/src/commands/sudo.py b/bittensor_cli/src/commands/sudo.py index 4ccf10226..b92f31cdc 100644 --- a/bittensor_cli/src/commands/sudo.py +++ b/bittensor_cli/src/commands/sudo.py @@ -22,7 +22,6 @@ from bittensor_cli.src.bittensor.utils import ( confirm_action, console, - err_console, print_error, print_verbose, normalize_hyperparameters, @@ -311,8 +310,8 @@ async def set_hyperparameter_extrinsic( ) extrinsic = parameter if not arbitrary_extrinsic: - err_msg = ":cross_mark: [red]Invalid hyperparameter specified.[/red]" - err_console.print(err_msg) + err_msg = "Invalid hyperparameter specified." + print_error(err_msg) return False, err_msg, None if sudo_ is RootSudoOnly.TRUE and prompt: if not confirm_action( @@ -342,7 +341,7 @@ async def set_hyperparameter_extrinsic( if len(value) < len(non_netuid_fields): err_msg = "Not enough values provided in the list for all parameters" - err_console.print(err_msg) + print_error(err_msg) return False, err_msg, None call_params.update( @@ -385,16 +384,14 @@ async def set_hyperparameter_extrinsic( ) else: if subnet_owner != coldkey_ss58: - err_msg = ":cross_mark: [red]This wallet doesn't own the specified subnet.[/red]" - err_console.print(err_msg) + err_msg = "This wallet doesn't own the specified subnet." + print_error(err_msg) return False, err_msg, None call = call_ else: if subnet_owner != coldkey_ss58: - err_msg = ( - ":cross_mark: [red]This wallet doesn't own the specified subnet.[/red]" - ) - err_console.print(err_msg) + err_msg = "This wallet doesn't own the specified subnet." + print_error(err_msg) return False, err_msg, None call = call_ with console.status( @@ -407,7 +404,7 @@ async def set_hyperparameter_extrinsic( call, wallet, wait_for_inclusion, wait_for_finalization, proxy=proxy ) if not success: - err_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}") + print_error(f"Failed: {err_msg}") return False, err_msg, None else: ext_id = await ext_receipt.get_extrinsic_identifier() @@ -448,7 +445,7 @@ async def _get_senate_members( decode_account_id(i[x][0]) for i in senate_members for x in range(len(i)) ] except (IndexError, TypeError): - err_console.print("Unable to retrieve senate members.") + print_error("Unable to retrieve senate members.") return [] @@ -476,7 +473,7 @@ async def get_proposal_call_data(p_hash: str) -> Optional[GenericCall]: f"0x{bytes(ph[0][x][0]).hex()}" for x in range(len(ph[0])) ] except (IndexError, TypeError): - err_console.print("Unable to retrieve proposal vote data") + print_error("Unable to retrieve proposal vote data") return {} call_data_, vote_data_ = await asyncio.gather( @@ -633,7 +630,7 @@ async def vote_senate_extrinsic( call, wallet, wait_for_inclusion, wait_for_finalization, proxy=proxy ) if not success: - err_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}") + print_error(f"Failed: {err_msg}") return False # Successful vote, final check for data else: @@ -648,8 +645,8 @@ async def vote_senate_extrinsic( return True else: # hotkey not found in ayes/nays - err_console.print( - ":cross_mark: [red]Unknown error. Couldn't find vote.[/red]" + print_error( + "Unknown error. Couldn't find vote." ) return False else: @@ -731,7 +728,7 @@ async def set_take_extrinsic( ) if not success: - err_console.print(err) + print_error(err) ext_id = None else: console.print( @@ -770,7 +767,7 @@ async def sudo_set_hyperparameter( sys.stdout.write(json_str + "\n") sys.stdout.flush() else: - err_console.print(err_msg) + print_error(err_msg) return False, err_msg, None if json_output: prompt = False @@ -1127,12 +1124,12 @@ async def senate_vote( """Vote in Bittensor's governance protocol proposals""" if not proposal_hash: - err_console.print( + print_error( "Aborting: Proposal hash not specified. View all proposals with the `proposals` command." ) return False elif not _validate_proposal_hash(proposal_hash): - err_console.print( + print_error( "Aborting. Proposal hash is invalid. Proposal hashes should start with '0x' and be 32 bytes long" ) return False @@ -1140,7 +1137,7 @@ async def senate_vote( print_verbose(f"Fetching senate status of {wallet.hotkey_str}") hotkey_ss58 = get_hotkey_pub_ss58(wallet) if not await _is_senate_member(subtensor, hotkey_ss58=hotkey_ss58): - err_console.print(f"Aborting: Hotkey {hotkey_ss58} isn't a senate member.") + print_error(f"Aborting: Hotkey {hotkey_ss58} isn't a senate member.") return False # Unlock the wallet. @@ -1150,7 +1147,7 @@ async def senate_vote( console.print(f"Fetching proposals in [dark_orange]network: {subtensor.network}") vote_data = await subtensor.get_vote_data(proposal_hash, reuse_block=True) if not vote_data: - err_console.print(":cross_mark: [red]Failed[/red]: Proposal not found.") + print_error("Failed: Proposal not found.") return False success = await vote_senate_extrinsic( @@ -1187,7 +1184,7 @@ async def set_take( async def _do_set_take() -> tuple[bool, Optional[str]]: if take > 0.18 or take < 0: - err_console.print("ERROR: Take value should not exceed 18% or be below 0%") + print_error("ERROR: Take value should not exceed 18% or be below 0%") return False, None block_hash = await subtensor.substrate.get_chain_head() @@ -1196,7 +1193,7 @@ async def _do_set_take() -> tuple[bool, Optional[str]]: hotkey_ss58, block_hash=block_hash ) if not len(netuids_registered) > 0: - err_console.print( + print_error( f"Hotkey [{COLOR_PALETTE.G.HK}]{hotkey_ss58}[/{COLOR_PALETTE.G.HK}] is not registered to" f" any subnet. Please register using [{COLOR_PALETTE.G.SUBHEAD}]`btcli subnets register`" f"[{COLOR_PALETTE.G.SUBHEAD}] and try again." @@ -1213,7 +1210,7 @@ async def _do_set_take() -> tuple[bool, Optional[str]]: success, ext_id = result if not success: - err_console.print("Could not set the take") + print_error("Could not set the take") return False, None else: new_take = await get_current_take(subtensor, wallet) @@ -1259,7 +1256,7 @@ async def trim( if json_output: json_console.print_json(data={"success": False, "message": err_msg}) else: - err_console.print(f":cross_mark: [red]{err_msg}[/red]") + print_error(err_msg) return False if prompt and not json_output: if not confirm_action( @@ -1268,7 +1265,7 @@ async def trim( decline=decline, quiet=quiet, ): - err_console.print(":cross_mark: [red]User aborted.[/red]") + print_error("User aborted.") call = await subtensor.substrate.compose_call( call_module="AdminUtils", call_function="sudo_trim_to_max_allowed_uids", @@ -1287,7 +1284,7 @@ async def trim( } ) else: - err_console.print(f":cross_mark: [red]{err_msg}[/red]") + print_error(err_msg) return False else: ext_id = await ext_receipt.get_extrinsic_identifier() diff --git a/bittensor_cli/src/commands/weights.py b/bittensor_cli/src/commands/weights.py index 4abbbde0c..a12f5b659 100644 --- a/bittensor_cli/src/commands/weights.py +++ b/bittensor_cli/src/commands/weights.py @@ -11,7 +11,7 @@ from bittensor_cli.src.bittensor.utils import ( confirm_action, - err_console, + print_error, console, format_error_message, json_console, @@ -146,7 +146,7 @@ async def commit_weights( commit_hash=commit_hash ) except SubstrateRequestException as e: - err_console.print(f"Error committing weights: {format_error_message(e)}") + print_error(f"Error committing weights: {format_error_message(e)}") # bittensor.logging.error(f"Error committing weights: {e}") success = False message = "No attempt made. Perhaps it is too soon to commit weights!" @@ -212,7 +212,7 @@ async def _commit_reveal( async with self.subtensor: return await self.reveal(weight_uids, weight_vals) else: - console.print(f":cross_mark: [red]Failed[/red]: error:{commit_msg}") + print_error(f"Failed: error:{commit_msg}") # bittensor.logging.error(msg=commit_msg, prefix="Set weights with hash commit", # suffix=f"Failed: {commit_msg}") return False, f"Failed to commit weights hash. {commit_msg}", None @@ -417,7 +417,7 @@ async def reveal_weights( if success: console.print("Weights revealed successfully") else: - err_console.print(f"Failed to reveal weights: {message}") + print_error(f"Failed to reveal weights: {message}") async def commit_weights( @@ -467,4 +467,4 @@ async def commit_weights( if success: console.print("Weights set successfully") else: - err_console.print(f"Failed to commit weights: {message}") + print_error(f"Failed to commit weights: {message}") From cd3329eaa4f0b4802dbfd3ca3430847a1817a74a Mon Sep 17 00:00:00 2001 From: leonace924 Date: Fri, 19 Dec 2025 10:10:03 -0500 Subject: [PATCH 5/9] fix: update to print_error in stake and subnets folder --- bittensor_cli/src/commands/stake/move.py | 37 ++++++----- bittensor_cli/src/commands/stake/remove.py | 9 ++- .../src/commands/subnets/mechanisms.py | 32 +++++----- bittensor_cli/src/commands/subnets/price.py | 17 +++--- bittensor_cli/src/commands/subnets/subnets.py | 61 +++++++++---------- 5 files changed, 76 insertions(+), 80 deletions(-) diff --git a/bittensor_cli/src/commands/stake/move.py b/bittensor_cli/src/commands/stake/move.py index b43ead425..379b451c3 100644 --- a/bittensor_cli/src/commands/stake/move.py +++ b/bittensor_cli/src/commands/stake/move.py @@ -15,7 +15,6 @@ from bittensor_cli.src.bittensor.utils import ( confirm_action, console, - err_console, print_error, group_subnets, get_subnet_name, @@ -532,8 +531,8 @@ async def move_stake( # Check enough to move. amount_to_move_as_balance.set_unit(origin_netuid) if amount_to_move_as_balance > origin_stake_balance: - err_console.print( - f"[red]Not enough stake[/red]:\n" + print_error( + f"Not enough stake:\n" f" Stake balance: [{COLOR_PALETTE.S.AMOUNT}]{origin_stake_balance}[/{COLOR_PALETTE.S.AMOUNT}]" f" < Moving amount: [{COLOR_PALETTE.S.AMOUNT}]{amount_to_move_as_balance}[/{COLOR_PALETTE.S.AMOUNT}]" ) @@ -615,7 +614,7 @@ async def move_stake( ) if not mev_success: status.stop() - err_console.print(f"\n:cross_mark: [red]Failed[/red]: {mev_error}") + print_error(f"\nFailed: {mev_error}") return False, "" await print_extrinsic_id(response) if not prompt: @@ -654,7 +653,7 @@ async def move_stake( ) return True, ext_id else: - err_console.print(f"\n:cross_mark: [red]Failed[/red] with error: {err_msg}") + print_error(f"\nFailed with error: {err_msg}") return False, "" @@ -712,11 +711,11 @@ async def transfer_stake( subtensor.subnet_exists(netuid=origin_netuid, block_hash=block_hash), ) if not dest_exists: - err_console.print(f"[red]Subnet {dest_netuid} does not exist[/red]") + print_error(f"Subnet {dest_netuid} does not exist") return False, "" if not origin_exists: - err_console.print(f"[red]Subnet {origin_netuid} does not exist[/red]") + print_error(f"Subnet {origin_netuid} does not exist") return False, "" # Get current stake balances @@ -734,8 +733,8 @@ async def transfer_stake( ) if current_stake.tao == 0: - err_console.print( - f"[red]No stake found for hotkey: {origin_hotkey} on netuid: {origin_netuid}[/red]" + print_error( + f"No stake found for hotkey: {origin_hotkey} on netuid: {origin_netuid}" ) return False, "" @@ -750,8 +749,8 @@ async def transfer_stake( # Check if enough stake to transfer if amount_to_transfer > current_stake: - err_console.print( - f"[red]Not enough stake to transfer[/red]:\n" + print_error( + f"Not enough stake to transfer:\n" f"Stake balance: [{COLOR_PALETTE.S.STAKE_AMOUNT}]{current_stake}[/{COLOR_PALETTE.S.STAKE_AMOUNT}] < " f"Transfer amount: [{COLOR_PALETTE.S.STAKE_AMOUNT}]{amount_to_transfer}[/{COLOR_PALETTE.S.STAKE_AMOUNT}]" ) @@ -831,7 +830,7 @@ async def transfer_stake( ) if not mev_success: status.stop() - err_console.print(f"\n:cross_mark: [red]Failed[/red]: {mev_error}") + print_error(f"\nFailed: {mev_error}") return False, "" await print_extrinsic_id(response) ext_id = await response.get_extrinsic_identifier() @@ -864,7 +863,7 @@ async def transfer_stake( return True, ext_id else: - err_console.print(f":cross_mark: [red]Failed[/red] with error: {err_msg}") + print_error(f"Failed with error: {err_msg}") return False, "" @@ -924,11 +923,11 @@ async def swap_stake( subtensor.subnet_exists(netuid=origin_netuid, block_hash=block_hash), ) if not dest_exists: - err_console.print(f"[red]Subnet {destination_netuid} does not exist[/red]") + print_error(f"Subnet {destination_netuid} does not exist") return False, "" if not origin_exists: - err_console.print(f"[red]Subnet {origin_netuid} does not exist[/red]") + print_error(f"Subnet {origin_netuid} does not exist") return False, "" # Get current stake balances @@ -951,8 +950,8 @@ async def swap_stake( # Check if enough stake to swap if amount_to_swap > current_stake: - err_console.print( - f"[red]Not enough stake to swap[/red]:\n" + print_error( + f"Not enough stake to swap:\n" f"Stake balance: [{COLOR_PALETTE.S.STAKE_AMOUNT}]{current_stake}[/{COLOR_PALETTE.S.STAKE_AMOUNT}] < " f"Swap amount: [{COLOR_PALETTE.S.STAKE_AMOUNT}]{amount_to_swap}[/{COLOR_PALETTE.S.STAKE_AMOUNT}]" ) @@ -1038,7 +1037,7 @@ async def swap_stake( ) if not mev_success: status.stop() - err_console.print(f"\n:cross_mark: [red]Failed[/red]: {mev_error}") + print_error(f"\nFailed: {mev_error}") return False, "" await print_extrinsic_id(response) if not prompt: @@ -1070,5 +1069,5 @@ async def swap_stake( return True, ext_id else: - err_console.print(f":cross_mark: [red]Failed[/red] with error: {err_msg}") + print_error(f"Failed with error: {err_msg}") return False, "" diff --git a/bittensor_cli/src/commands/stake/remove.py b/bittensor_cli/src/commands/stake/remove.py index 216332420..1cc7116a5 100644 --- a/bittensor_cli/src/commands/stake/remove.py +++ b/bittensor_cli/src/commands/stake/remove.py @@ -18,7 +18,6 @@ from bittensor_cli.src.bittensor.utils import ( confirm_action, console, - err_console, print_verbose, print_error, get_hotkey_wallets_for_wallet, @@ -203,8 +202,8 @@ async def unstake( # Check enough stake to remove. amount_to_unstake_as_balance.set_unit(netuid) if amount_to_unstake_as_balance > current_stake_balance: - err_console.print( - f"[red]Not enough stake to remove[/red]:\n" + print_error( + f"Not enough stake to remove:\n" f" Stake balance: [dark_orange]{current_stake_balance}[/dark_orange]" f" < Unstaking amount: [dark_orange]{amount_to_unstake_as_balance}[/dark_orange]" f" on netuid: {netuid}" @@ -658,7 +657,7 @@ async def _unstake_extrinsic( ) if not mev_success: status.stop() - err_console.print(f"\n:cross_mark: [red]Failed[/red]: {mev_error}") + print_error(f"\nFailed: {mev_error}") return False, None await print_extrinsic_id(response) block_hash = await subtensor.substrate.get_chain_head() @@ -772,7 +771,7 @@ async def _safe_unstake_extrinsic( ) if not mev_success: status.stop() - err_console.print(f"\n:cross_mark: [red]Failed[/red]: {mev_error}") + print_error(f"\nFailed: {mev_error}") return False, None await print_extrinsic_id(response) block_hash = await subtensor.substrate.get_chain_head() diff --git a/bittensor_cli/src/commands/subnets/mechanisms.py b/bittensor_cli/src/commands/subnets/mechanisms.py index e9d1c7223..2400be707 100644 --- a/bittensor_cli/src/commands/subnets/mechanisms.py +++ b/bittensor_cli/src/commands/subnets/mechanisms.py @@ -12,7 +12,7 @@ from bittensor_cli.src.bittensor.utils import ( confirm_action, console, - err_console, + print_error, json_console, U16_MAX, print_extrinsic_id, @@ -31,7 +31,7 @@ async def count( block_hash = await subtensor.substrate.get_chain_head() if not await subtensor.subnet_exists(netuid=netuid, block_hash=block_hash): - err_console.print(f"[red]Subnet {netuid} does not exist[/red]") + print_error(f"Subnet {netuid} does not exist") if json_output: json_console.print_json( data={"success": False, "error": f"Subnet {netuid} does not exist"} @@ -55,7 +55,7 @@ async def count( } ) else: - err_console.print( + print_error( "Subnet mechanism count: [red]Failed to get mechanism count[/red]" ) return None @@ -205,7 +205,7 @@ async def set_emission_split( if json_output: json_console.print_json(data={"success": False, "error": message}) else: - err_console.print(message) + print_error(message) return False if not json_output: @@ -233,11 +233,11 @@ async def set_emission_split( if json_output: json_console.print_json(data={"success": False, "error": message}) else: - err_console.print(message) + print_error(message) return False else: if not prompt: - err_console.print( + print_error( "Split values not supplied with `--no-prompt` flag. Cannot continue." ) return False @@ -264,7 +264,7 @@ async def set_emission_split( try: weights.append(float(response)) except ValueError: - err_console.print("Invalid number provided. Aborting.") + print_error("Invalid number provided. Aborting.") return False if len(weights) != mech_count: @@ -272,7 +272,7 @@ async def set_emission_split( if json_output: json_console.print_json(data={"success": False, "error": message}) else: - err_console.print(message) + print_error(message) return False if any(value < 0 for value in weights): @@ -280,7 +280,7 @@ async def set_emission_split( if json_output: json_console.print_json(data={"success": False, "error": message}) else: - err_console.print(message) + print_error(message) return False try: @@ -290,7 +290,7 @@ async def set_emission_split( if json_output: json_console.print_json(data={"success": False, "error": message}) else: - err_console.print(message) + print_error(message) return False if normalized_weights == existing_split: @@ -357,7 +357,7 @@ async def set_emission_split( decline=decline, quiet=quiet, ): - console.print(":cross_mark: Aborted!") + print_error("Aborted!") return False success, err_msg, ext_id = await set_mechanism_emission( @@ -428,13 +428,13 @@ async def set_mechanism_count( if mechanism_count < 1: err_msg = "Mechanism count must be greater than or equal to one." if not json_output: - err_console.print(err_msg) + print_error(err_msg) return False, err_msg, None if not await subtensor.subnet_exists(netuid): err_msg = f"Subnet with netuid {netuid} does not exist." if not json_output: - err_console.print(err_msg) + print_error(err_msg) return False, err_msg, None if not confirm_action( @@ -467,7 +467,7 @@ async def set_mechanism_count( f"[dark_sea_green3]Mechanism count set to {mechanism_count} for subnet {netuid}[/dark_sea_green3]" ) else: - err_console.print(f":cross_mark: [red]{err_msg}[/red]") + print_error(f"Failed: {err_msg}") return success, err_msg, ext_id @@ -487,7 +487,7 @@ async def set_mechanism_emission( if not split: err_msg = "Emission split must include at least one weight." if not json_output: - err_console.print(err_msg) + print_error(err_msg) return False, err_msg, None success, err_msg, ext_receipt = await sudo.set_mechanism_emission_extrinsic( @@ -511,6 +511,6 @@ async def set_mechanism_emission( f"[dark_sea_green3]Emission split updated for subnet {netuid}[/dark_sea_green3]" ) else: - err_console.print(f":cross_mark: [red]{err_msg}[/red]") + print_error(f"Failed: {err_msg}") return success, err_msg, ext_id diff --git a/bittensor_cli/src/commands/subnets/price.py b/bittensor_cli/src/commands/subnets/price.py index 8e488a95c..7f886f2be 100644 --- a/bittensor_cli/src/commands/subnets/price.py +++ b/bittensor_cli/src/commands/subnets/price.py @@ -13,7 +13,6 @@ from bittensor_cli.src.bittensor.chain_data import DynamicInfo from bittensor_cli.src.bittensor.utils import ( console, - err_console, get_subnet_name, print_error, json_console, @@ -83,7 +82,7 @@ async def price( block_numbers, all_subnet_infos, netuids, all_netuids ) if not subnet_data: - err_console.print("[red]No valid price data found for any subnet[/red]") + print_error("No valid price data found for any subnet") return if html_output: @@ -167,9 +166,9 @@ def _process_subnet_data(block_numbers, all_subnet_infos, netuids, all_netuids): continue if len(prices) < 5: - err_console.print( - f"[red]Insufficient price data for subnet {netuid}. " - f"Need at least 5 data points but only found {len(prices)}.[/red]" + print_error( + f"Insufficient price data for subnet {netuid}. " + f"Need at least 5 data points but only found {len(prices)}." ) continue @@ -203,13 +202,13 @@ def _process_subnet_data(block_numbers, all_subnet_infos, netuids, all_netuids): valid_subnet_infos.append(subnet_info) if not valid_subnet_infos or not prices: - err_console.print("[red]No valid price data found for any subnet[/red]") + print_error("No valid price data found for any subnet") return {} if len(prices) < 5: - err_console.print( - f"[red]Insufficient price data for subnet {netuids[0]}. " - f"Need at least 5 data points but only found {len(prices)}.[/red]" + print_error( + f"Insufficient price data for subnet {netuids[0]}. " + f"Need at least 5 data points but only found {len(prices)}." ) return {} diff --git a/bittensor_cli/src/commands/subnets/subnets.py b/bittensor_cli/src/commands/subnets/subnets.py index 77c9a16b7..23199898a 100644 --- a/bittensor_cli/src/commands/subnets/subnets.py +++ b/bittensor_cli/src/commands/subnets/subnets.py @@ -30,7 +30,6 @@ confirm_action, console, create_and_populate_table, - err_console, print_verbose, print_error, get_metadata_table, @@ -171,7 +170,7 @@ async def _find_event_attributes_in_extrinsic_receipt( print_verbose("Fetching burn_cost") sn_burn_cost = await burn_cost(subtensor) if sn_burn_cost > your_balance: - err_console.print( + print_error( f"Your balance of: [{COLOR_PALETTE.POOLS.TAO}]{your_balance}[{COLOR_PALETTE.POOLS.TAO}]" f" is not enough to burn " f"[{COLOR_PALETTE.POOLS.TAO}]{sn_burn_cost}[{COLOR_PALETTE.POOLS.TAO}] " @@ -229,8 +228,8 @@ async def _find_event_attributes_in_extrinsic_receipt( for field, value in identity_data.items(): max_size = 64 # bytes if len(value) > max_size: - err_console.print( - f"[red]Error:[/red] Identity field [white]{field}[/white] must be <= {max_size} bytes.\n" + print_error( + f"Error: Identity field [white]{field}[/white] must be <= {max_size} bytes.\n" f"Value '{value.decode()}' is {len(value)} bytes." ) return False, None, None @@ -265,7 +264,7 @@ async def _find_event_attributes_in_extrinsic_receipt( return True, None, None if not success: - err_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}") + print_error(f"Failed: {err_msg}") return False, None, None else: # Check for MEV shield execution @@ -281,8 +280,8 @@ async def _find_event_attributes_in_extrinsic_receipt( ) if not mev_success: status.stop() - err_console.print( - f":cross_mark: [red]Failed[/red]: MEV execution failed: {mev_error}" + print_error( + f"Failed: MEV execution failed: {mev_error}" ) return False, None, None @@ -1088,11 +1087,11 @@ async def show_root(): return False if root_state is None: - err_console.print("The root subnet does not exist") + print_error("The root subnet does not exist") return if len(root_state.hotkeys) == 0: - err_console.print( + print_error( "The root-subnet is currently empty with 0 UIDs registered." ) return @@ -1299,7 +1298,7 @@ async def show_subnet( with console.status(":satellite: Retrieving subnet information..."): block_hash = await subtensor.substrate.get_chain_head() if not await subtensor.subnet_exists(netuid=netuid_, block_hash=block_hash): - err_console.print(f"[red]Subnet {netuid_} does not exist[/red]") + print_error(f"Subnet {netuid_} does not exist") return False ( subnet_info, @@ -1719,8 +1718,8 @@ async def burn_cost( ) ) else: - err_console.print( - "Subnet burn cost: [red]Failed to get subnet burn cost[/red]" + print_error( + "Subnet burn cost: Failed to get subnet burn cost" ) return None @@ -1777,7 +1776,7 @@ async def create( decline=decline, quiet=quiet, ): - console.print(":cross_mark: Aborted!") + print_error("Aborted!") return False identity = prompt_for_identity( @@ -1864,7 +1863,7 @@ async def _storage_key(storage_fn: str) -> StorageKey: print_verbose("Checking subnet status") block_hash = await subtensor.substrate.get_chain_head() if not await subtensor.subnet_exists(netuid=netuid, block_hash=block_hash): - err_console.print(f"[red]Subnet {netuid} does not exist[/red]") + print_error(f"Subnet {netuid} does not exist") if json_output: json_console.print_json( data={ @@ -1890,7 +1889,7 @@ async def _storage_key(storage_fn: str) -> StorageKey: # Check balance is sufficient if balance < current_recycle: err_msg = f"Insufficient balance {balance} to register neuron. Current recycle is {current_recycle} TAO" - err_console.print(f"[red]{err_msg}[/red]") + print_error(err_msg) if json_output: json_console.print_json( data={"success": False, "msg": err_msg, "extrinsic_identifier": None} @@ -1977,7 +1976,7 @@ async def _storage_key(storage_fn: str) -> StorageKey: proxy=proxy, ) if not success: - err_console.print(f":cross_mark:[red]Failure[/red]: {msg}") + print_error(f"Failure: {msg}") print_verbose("Checking registration allowed and limits") storage_key_results, current_block = await asyncio.gather( subtensor.substrate.query_multi( @@ -2000,8 +1999,8 @@ async def _storage_key(storage_fn: str) -> StorageKey: ) = [x[1] for x in storage_key_results] if not registration_allowed: - err_console.print( - f"[red]Registration to subnet {netuid} is not allowed[/red]" + print_error( + f"Registration to subnet {netuid} is not allowed" ) if json_output: json_console.print_json( @@ -2016,8 +2015,8 @@ async def _storage_key(storage_fn: str) -> StorageKey: if registrations_this_interval >= target_registrations_per_interval * 3: next_adjustment_block = last_adjustment_block + adjustment_interval remaining_blocks = next_adjustment_block - current_block - err_console.print( - f"[red]Registration to subnet {netuid} is full for this interval.[/red] " + print_error( + f"Registration to subnet {netuid} is full for this interval. " f"Try again in {remaining_blocks} blocks." ) if json_output: @@ -2208,8 +2207,8 @@ async def metagraph_cmd( metadata_info = get_metadata_table("metagraph") table_data = json.loads(metadata_info["table_data"]) except sqlite3.OperationalError: - err_console.print( - "[red]Error[/red] Unable to retrieve table data. This is usually caused by attempting to use " + print_error( + "Error: Unable to retrieve table data. This is usually caused by attempting to use " "`--reuse-last` before running the command a first time. In rare cases, this could also be due to " "a corrupted database. Re-run the command (do not use `--reuse-last`) and see if that resolves your " "issue." @@ -2296,8 +2295,8 @@ async def metagraph_cmd( ], ) except sqlite3.OperationalError: - err_console.print( - "[red]Error[/red] Unable to retrieve table data. This may indicate that your database is corrupted, " + print_error( + "Error: Unable to retrieve table data. This may indicate that your database is corrupted, " "or was not able to load with the most recent data." ) return @@ -2590,7 +2589,7 @@ async def set_identity( sn_exists = await subtensor.subnet_exists(netuid) if not sn_exists: - err_console.print(f"Subnet {netuid} does not exist") + print_error(f"Subnet {netuid} does not exist") return False, None identity_data = { @@ -2631,7 +2630,7 @@ async def set_identity( ) if not success: - err_console.print(f"[red]:cross_mark: Failed![/red] {err_msg}") + print_error(f"Failed: {err_msg}") return False, None ext_id = await ext_receipt.get_extrinsic_identifier() await print_extrinsic_id(ext_receipt) @@ -2683,7 +2682,7 @@ async def get_identity( identity = subnet.subnet_identity if subnet else None if not identity: - err_console.print( + print_error( f"Existing subnet identity not found" f" for subnet [blue]{netuid}[/blue]" f" on {subtensor}" @@ -2788,7 +2787,7 @@ async def start_subnet( ) # TODO should this check against proxy as well? if subnet_owner != coldkey_ss58: - print_error(":cross_mark: This wallet doesn't own the specified subnet.") + print_error("This wallet doesn't own the specified subnet.") return False if prompt: @@ -2832,7 +2831,7 @@ async def start_subnet( return True await get_start_schedule(subtensor, netuid) - print_error(f":cross_mark: Failed to start subnet: {error_msg}") + print_error(f"Failed to start subnet: {error_msg}") return False @@ -2861,7 +2860,7 @@ async def set_symbol( data={"success": False, "message": err, "extrinsic_identifier": None} ) else: - err_console.print(err) + print_error(err) return False if prompt and not json_output: @@ -2916,5 +2915,5 @@ async def set_symbol( } ) else: - err_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}") + print_error(f"Failed: {err_msg}") return False From 01351f54307c959116b36b0758a1692b0d283ea4 Mon Sep 17 00:00:00 2001 From: leonace924 Date: Fri, 19 Dec 2025 10:12:50 -0500 Subject: [PATCH 6/9] fix: update to print_error in cli.py file --- bittensor_cli/cli.py | 102 +++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index ae7d04709..f34c6491e 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -546,7 +546,7 @@ def get_optional_netuid(netuid: Optional[int], all_netuids: bool) -> Optional[in try: return int(answer) except ValueError: - err_console.print(f"Invalid netuid: {answer}") + print_error(f"Invalid netuid: {answer}") return get_optional_netuid(None, False) else: return netuid @@ -575,12 +575,12 @@ def parse_mnemonic(mnemonic: str) -> str: key=lambda x: int(x[0]), ) if int(items[0][0]) != 1: - err_console.print("Numbered mnemonics must begin with 1") + print_error("Numbered mnemonics must begin with 1") raise typer.Exit() if [int(x[0]) for x in items] != list( range(int(items[0][0]), int(items[-1][0]) + 1) ): - err_console.print( + print_error( "Missing or duplicate numbers in a numbered mnemonic. " "Double-check your numbered mnemonics and try again." ) @@ -731,12 +731,12 @@ def debug_callback(value: bool): or os.path.expanduser(defaults.config.debug_file_path) ) if not debug_file_loc.exists(): - err_console.print( - f"[red]Error: The debug file '{arg__(str(debug_file_loc))}' does not exist. This indicates that you have" + print_error( + f"Error: The debug file '{arg__(str(debug_file_loc))}' does not exist. This indicates that you have" f" not run a command which has logged debug output, or you deleted this file. Debug logging only occurs" f" if {arg__('use_cache')} is set to True in your config ({arg__('btcli config set')}). If the debug " f"file was created using the {arg__('BTCLI_DEBUG_FILE')} environment variable, please set the value for" - f" the same location, and re-run this {arg__('btcli --debug')} command.[/red]" + f" the same location, and re-run this {arg__('btcli --debug')} command." ) raise typer.Exit() save_file_loc_ = Prompt.ask( @@ -1474,7 +1474,7 @@ async def _run(): result = await cmd return result except (ConnectionRefusedError, ssl.SSLError, InvalidHandshake): - err_console.print(f"Unable to connect to the chain: {self.subtensor}") + print_error(f"Unable to connect to the chain: {self.subtensor}") verbose_console.print(traceback.format_exc()) exception_occurred = True except ( @@ -1484,13 +1484,13 @@ async def _run(): RuntimeError, ) as e: if isinstance(e, SubstrateRequestException): - err_console.print(str(e)) + print_error(str(e)) elif isinstance(e, RuntimeError): pass # Temporarily to handle loop bound issues verbose_console.print(traceback.format_exc()) exception_occurred = True except Exception as e: - err_console.print(f"An unknown error has occurred: {e}") + print_error(f"An unknown error has occurred: {e}") verbose_console.print(traceback.format_exc()) exception_occurred = True finally: @@ -1504,7 +1504,7 @@ async def _run(): await self.subtensor.substrate.close() except Exception as e: # ensures we always exit cleanly if not isinstance(e, (typer.Exit, RuntimeError)): - err_console.print(f"An unknown error has occurred: {e}") + print_error(f"An unknown error has occurred: {e}") if exception_occurred: raise typer.Exit() @@ -1623,7 +1623,7 @@ def verbosity_handler( "The '--no' flag requires prompts to be enabled." ) if quiet and verbose: - err_console.print("Cannot specify both `--quiet` and `--verbose`") + print_error("Cannot specify both `--quiet` and `--verbose`") raise typer.Exit() if json_output and verbose: verbosity_console_handler(3) @@ -2008,7 +2008,7 @@ def config_add_proxy( Adds a new pure proxy to the address book. """ if self.proxies.get(name) is not None: - err_console.print( + print_error( f"Proxy {name} already exists. Use `btcli config update-proxy` to update it." ) raise typer.Exit() @@ -2059,7 +2059,7 @@ def config_remove_proxy( ProxyAddressBook.delete_entry(conn, cursor, name=name) console.print(f"Removed {name} from the address book.") else: - err_console.print(f"Proxy {name} not found in address book.") + print_error(f"Proxy {name} not found in address book.") self.config_get_proxies() def config_get_proxies(self): @@ -2114,7 +2114,7 @@ def config_update_proxy( note: Optional[str] = typer.Option(None, help="Any notes about this entry"), ): if name not in self.proxies: - err_console.print(f"Proxy {name} not found in address book.") + print_error(f"Proxy {name} not found in address book.") return else: if isinstance(proxy_type, ProxyType): @@ -2298,12 +2298,12 @@ def ask_subnet_mechanism( """Resolve the mechanism ID to use.""" if mechanism_count is None or mechanism_count <= 0: - err_console.print(f"Subnet {netuid} does not exist.") + print_error(f"Subnet {netuid} does not exist.") raise typer.Exit() if mechanism_id is not None: if mechanism_id < 0 or mechanism_id >= mechanism_count: - err_console.print( + print_error( f"Mechanism ID {mechanism_id} is out of range for subnet {netuid}. " f"Valid range: [bold cyan]0 to {mechanism_count - 1}[/bold cyan]." ) @@ -2321,7 +2321,7 @@ def ask_subnet_mechanism( ) if 0 <= selected_mechanism_id < mechanism_count: return selected_mechanism_id - err_console.print( + print_error( f"Mechanism ID {selected_mechanism_id} is out of range for subnet {netuid}. " f"Valid range: [bold cyan]0 to {mechanism_count - 1}[/bold cyan]." ) @@ -2402,16 +2402,16 @@ def wallet_ask( if validate == WV.WALLET or validate == WV.WALLET_AND_HOTKEY: valid = utils.is_valid_wallet(wallet) if not valid[0]: - utils.err_console.print( - f"[red]Error: Wallet does not exist. \n" - f"Please verify your wallet information: {wallet}[/red]" + print_error( + f"Error: Wallet does not exist. \n" + f"Please verify your wallet information: {wallet}" ) raise typer.Exit() if validate == WV.WALLET_AND_HOTKEY and not valid[1]: - utils.err_console.print( - f"[red]Error: Wallet '{wallet.name}' exists but the hotkey '{wallet.hotkey_str}' does not. \n" - f"Please verify your wallet information: {wallet}[/red]" + print_error( + f"Error: Wallet '{wallet.name}' exists but the hotkey '{wallet.hotkey_str}' does not. \n" + f"Please verify your wallet information: {wallet}" ) raise typer.Exit() if return_wallet_and_hotkey: @@ -2428,8 +2428,8 @@ def wallet_ask( ) ).strip() if not is_valid_ss58_address(hotkey): - err_console.print( - f"[red]Error: {hotkey} is not valid SS58 address." + print_error( + f"Error: {hotkey} is not valid SS58 address." ) raise typer.Exit(1) else: @@ -2530,8 +2530,8 @@ def wallet_overview( """ self.verbosity_handler(quiet, verbose, json_output, False) if include_hotkeys and exclude_hotkeys: - utils.err_console.print( - "[red]You have specified both the inclusion and exclusion options. Only one of these options is allowed currently." + print_error( + "You have specified both the inclusion and exclusion options. Only one of these options is allowed currently." ) raise typer.Exit() @@ -6049,7 +6049,7 @@ def stake_get_children( ) if all_netuids and netuid: - err_console.print("Specify either a netuid or `--all`, not both.") + print_error("Specify either a netuid or `--all`, not both.") raise typer.Exit() if all_netuids: @@ -6125,11 +6125,11 @@ def stake_set_children( ) if len(proportions) != len(children): - err_console.print("You must have as many proportions as you have children.") + print_error("You must have as many proportions as you have children.") raise typer.Exit() if sum(proportions) > 1.0: - err_console.print("Your proportion total must not exceed 1.0.") + print_error("Your proportion total must not exceed 1.0.") raise typer.Exit() wallet = self.wallet_ask( @@ -6210,7 +6210,7 @@ def stake_revoke_children( validate=WV.WALLET_AND_HOTKEY, ) if all_netuids and netuid: - err_console.print("Specify either a netuid or '--all', not both.") + print_error("Specify either a netuid or '--all', not both.") raise typer.Exit() if all_netuids: netuid = None @@ -6305,7 +6305,7 @@ def stake_childkey_take( validate=WV.WALLET_AND_HOTKEY, ) if all_netuids and netuid: - err_console.print("Specify either a netuid or '--all', not both.") + print_error("Specify either a netuid or '--all', not both.") raise typer.Exit() if all_netuids: netuid = None @@ -6401,7 +6401,7 @@ def mechanism_count_set( if mechanism_count is None: if not prompt: - err_console.print( + print_error( "Mechanism count not supplied with `--no-prompt` flag. Cannot continue." ) return False @@ -6644,7 +6644,7 @@ def sudo_set( if not param_name: if not prompt: - err_console.print( + print_error( "Param name not supplied with `--no-prompt` flag. Cannot continue" ) return False @@ -6734,7 +6734,7 @@ def sudo_set( sys.stdout.write(json_str + "\n") sys.stdout.flush() else: - err_console.print( + print_error( f"[{COLORS.SU.HYPERPARAM}]alpha_high[/{COLORS.SU.HYPERPARAM}] and " f"[{COLORS.SU.HYPERPARAM}]alpha_low[/{COLORS.SU.HYPERPARAM}] " f"values cannot be set with `--no-prompt`" @@ -6762,7 +6762,7 @@ def sudo_set( sys.stdout.write(json_str + "\n") sys.stdout.flush() else: - err_console.print( + print_error( f"[{COLORS.SU.HYPERPARAM}]yuma_version[/{COLORS.SU.HYPERPARAM}]" f" is set using a different hyperparameter, and thus cannot be set with `--no-prompt`" ) @@ -6798,7 +6798,7 @@ def sudo_set( sys.stdout.write(json_str + "\n") sys.stdout.flush() else: - err_console.print( + print_error( f"[{COLORS.SU.HYPERPARAM}]subnet_is_active[/{COLORS.SU.HYPERPARAM}] " f"is set by using {arg__('btcli subnets start')} command." ) @@ -6806,7 +6806,7 @@ def sudo_set( if not param_value: if not prompt: - err_console.print( + print_error( "Param value not supplied with `--no-prompt` flag. Cannot continue." ) return False @@ -7285,8 +7285,8 @@ def subnets_price( if not current_only and subtensor.network in non_archives + [ Constants.network_map[x] for x in non_archives ]: - err_console.print( - f"[red]Error[/red] Running this command without {arg__('--current')} requires use of an archive node. " + print_error( + f"Error: Running this command without {arg__('--current')} requires use of an archive node. " f"Try running again with the {arg__('--network archive')} flag." ) return False @@ -7921,7 +7921,7 @@ def subnets_metagraph( """ self.verbosity_handler(quiet, verbose, json_output=False, prompt=False) if (reuse_last or html_output) and self.config.get("use_cache") is False: - err_console.print( + print_error( "Unable to use `--reuse-last` or `--html` when config `no-cache` is set to `True`. " "Set the`no-cache` field to `False` by using `btcli config set` or editing the config.yml file." ) @@ -7988,7 +7988,7 @@ def subnets_set_symbol( self.verbosity_handler(quiet, verbose, json_output, prompt, decline) proxy = self.is_valid_proxy_name_or_ss58(proxy, announce_only) if len(symbol) > 1: - err_console.print("Your symbol must be a single character.") + print_error("Your symbol must be a single character.") return False wallet = self.wallet_ask( wallet_name, @@ -8084,7 +8084,7 @@ def weights_reveal( ) if len(uids) != len(weights): - err_console.print( + print_error( "The number of UIDs you specify must match up with the specified number of weights" ) return @@ -8186,7 +8186,7 @@ def weights_commit( "Corresponding weights for the specified UIDs (eg: 0.2,0.3,0.4)", ) if len(uids) != len(weights): - err_console.print( + print_error( "The number of UIDs you specify must match up with the specified number of weights" ) return @@ -8360,7 +8360,7 @@ def liquidity_add( ) if price_low >= price_high: - err_console.print("The low price must be lower than the high price.") + print_error("The low price must be lower than the high price.") return False logger.debug( f"args:\n" @@ -9573,8 +9573,8 @@ def proxy_execute_announced( got_delay_from_config = True elif len(potential_matches) > 1: if not prompt: - err_console.print( - f":cross_mark:[red]Error: The proxy ss58 you provided: {proxy} matched the address book" + print_error( + f"Error: The proxy ss58 you provided: {proxy} matched the address book" f" ambiguously (more than one match). To use this (rather than the address book name), you will " f"have to use without {arg__('--no-prompt')}" ) @@ -9635,8 +9635,8 @@ def proxy_execute_announced( got_call_from_db = potential_call_matches[0][0] elif len(potential_call_matches) > 1: if not prompt: - err_console.print( - f":cross_mark:[red]Error: The call hash you have provided matches {len(potential_call_matches)}" + print_error( + f"Error: The call hash you have provided matches {len(potential_call_matches)}" f" possible entries. In order to choose which one, you will need to run " f"without {arg__('--no-prompt')}" ) @@ -9710,7 +9710,7 @@ def convert( Allows for converting between tao and rao using the specified flags """ if from_tao is None and from_rao is None: - err_console.print("Specify `--rao` and/or `--tao`.") + print_error("Specify `--rao` and/or `--tao`.") raise typer.Exit() if from_rao is not None: rao = int(float(from_rao)) @@ -9747,7 +9747,7 @@ def best_connection( """ additional_networks = additional_networks or [] if any(not x.startswith("ws") for x in additional_networks): - err_console.print( + print_error( "Invalid network endpoint. Ensure you are specifying a valid websocket endpoint" f" (starting with [{COLORS.G.LINKS}]ws://[/{COLORS.G.LINKS}] or " f"[{COLORS.G.LINKS}]wss://[/{COLORS.G.LINKS}]).", From 710f968e1f9fa6ee3686ad6c4c1d497b46db51f4 Mon Sep 17 00:00:00 2001 From: leonace924 Date: Fri, 19 Dec 2025 10:29:08 -0500 Subject: [PATCH 7/9] ruff foramt --- bittensor_cli/cli.py | 4 +--- .../src/bittensor/extrinsics/registration.py | 15 ++++----------- bittensor_cli/src/bittensor/extrinsics/root.py | 4 +--- .../src/bittensor/extrinsics/serving.py | 8 ++------ bittensor_cli/src/bittensor/utils.py | 4 +--- bittensor_cli/src/commands/proxy.py | 4 +--- .../src/commands/stake/children_hotkeys.py | 16 ++++------------ bittensor_cli/src/commands/stake/claim.py | 16 ++++------------ bittensor_cli/src/commands/subnets/subnets.py | 16 ++++------------ bittensor_cli/src/commands/sudo.py | 4 +--- bittensor_cli/src/commands/wallets.py | 4 +--- 11 files changed, 24 insertions(+), 71 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index f34c6491e..c407e5b9b 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -2428,9 +2428,7 @@ def wallet_ask( ) ).strip() if not is_valid_ss58_address(hotkey): - print_error( - f"Error: {hotkey} is not valid SS58 address." - ) + print_error(f"Error: {hotkey} is not valid SS58 address.") raise typer.Exit(1) else: return wallet, hotkey diff --git a/bittensor_cli/src/bittensor/extrinsics/registration.py b/bittensor_cli/src/bittensor/extrinsics/registration.py index ff6831a6e..c10929301 100644 --- a/bittensor_cli/src/bittensor/extrinsics/registration.py +++ b/bittensor_cli/src/bittensor/extrinsics/registration.py @@ -635,9 +635,7 @@ async def get_neuron_for_pubkey_and_subnet(): f"[bold]subnet:{netuid}[/bold][/dark_sea_green3]" ) return True - print_error( - f"Failed: {err_msg}" - ) + print_error(f"Failed: {err_msg}") await asyncio.sleep(0.5) # Successful registration, final check for neuron and pubkey @@ -655,9 +653,7 @@ async def get_neuron_for_pubkey_and_subnet(): return True else: # neuron not found, try again - print_error( - "Unknown error. Neuron not found." - ) + print_error("Unknown error. Neuron not found.") continue else: # Exited loop because pow is no longer valid. @@ -808,9 +804,7 @@ async def burned_register_extrinsic( return True, f"Registered on {netuid} with UID {my_uid}", ext_id else: # neuron not found, try again - print_error( - "Unknown error. Neuron not found." - ) + print_error("Unknown error. Neuron not found.") return False, "Unknown error. Neuron not found.", ext_id @@ -937,8 +931,7 @@ async def run_faucet_extrinsic( # process if registration successful, try again if pow is still valid if not await response.is_success: print_error( - f"Failed: " - f"{format_error_message(await response.error_message)}" + f"Failed: {format_error_message(await response.error_message)}" ) if attempts == max_allowed_attempts: raise MaxAttemptsException diff --git a/bittensor_cli/src/bittensor/extrinsics/root.py b/bittensor_cli/src/bittensor/extrinsics/root.py index 25870e544..2c346a47d 100644 --- a/bittensor_cli/src/bittensor/extrinsics/root.py +++ b/bittensor_cli/src/bittensor/extrinsics/root.py @@ -383,9 +383,7 @@ async def root_register_extrinsic( return True, f"Registered with UID {uid}", ext_id else: # neuron not found, try again - print_error( - "Unknown error. Neuron not found." - ) + print_error("Unknown error. Neuron not found.") return False, "Unknown error. Neuron not found.", ext_id diff --git a/bittensor_cli/src/bittensor/extrinsics/serving.py b/bittensor_cli/src/bittensor/extrinsics/serving.py index 3c26b5dbf..14945d46c 100644 --- a/bittensor_cli/src/bittensor/extrinsics/serving.py +++ b/bittensor_cli/src/bittensor/extrinsics/serving.py @@ -132,9 +132,7 @@ async def reset_axon_extrinsic( except Exception as e: error_message = format_error_message(e) - print_error( - f"Failed to reset axon: {error_message}" - ) + print_error(f"Failed to reset axon: {error_message}") return False, error_message, None @@ -252,7 +250,5 @@ async def set_axon_extrinsic( except Exception as e: error_message = format_error_message(e) - print_error( - f"Failed to set axon: {error_message}" - ) + print_error(f"Failed to set axon: {error_message}") return False, error_message, None diff --git a/bittensor_cli/src/bittensor/utils.py b/bittensor_cli/src/bittensor/utils.py index 8f8b9c943..41a120b63 100644 --- a/bittensor_cli/src/bittensor/utils.py +++ b/bittensor_cli/src/bittensor/utils.py @@ -132,9 +132,7 @@ def coldkeypub(self): def print_console(message: str, colour: str, console_: Console, title: str = ""): title_part = f"[bold {colour}][{title}]:[/bold {colour}] " if title else "" - console_.print( - f"{title_part}[{colour}]{message}[/{colour}]\n" - ) + console_.print(f"{title_part}[{colour}]{message}[/{colour}]\n") def print_verbose(message: str, status=None): diff --git a/bittensor_cli/src/commands/proxy.py b/bittensor_cli/src/commands/proxy.py index 0b7835fcd..bbca6d0e0 100644 --- a/bittensor_cli/src/commands/proxy.py +++ b/bittensor_cli/src/commands/proxy.py @@ -608,9 +608,7 @@ async def execute_announced( else: value = False else: - print_error( - f"Unrecognized type name {type_name}. {failure_}" - ) + print_error(f"Unrecognized type name {type_name}. {failure_}") return False call_args[arg] = value inner_call = await subtensor.substrate.compose_call( diff --git a/bittensor_cli/src/commands/stake/children_hotkeys.py b/bittensor_cli/src/commands/stake/children_hotkeys.py index f61e1a680..d4fb17998 100644 --- a/bittensor_cli/src/commands/stake/children_hotkeys.py +++ b/bittensor_cli/src/commands/stake/children_hotkeys.py @@ -573,9 +573,7 @@ async def set_children( ":white_heavy_check_mark: [green]Set children hotkeys.[/green]" ) else: - console.print( - f"Unable to set children hotkeys. {message}" - ) + console.print(f"Unable to set children hotkeys. {message}") else: # set children on all subnets that parent is registered on netuids = await subtensor.get_all_subnet_netuids() @@ -661,9 +659,7 @@ async def revoke_children( f"It will be completed around block {completion_block}. The current block is {current_block}" ) else: - console.print( - f"Unable to revoke children hotkeys. {message}" - ) + console.print(f"Unable to revoke children hotkeys. {message}") else: # revoke children from ALL netuids netuids = await subtensor.get_all_subnet_netuids() @@ -730,9 +726,7 @@ async def childkey_take( def validate_take_value(take_value: float) -> bool: if not (0 <= take_value <= 0.18): - print_error( - f"Invalid take value: {take_value}" - ) + print_error(f"Invalid take value: {take_value}") return False return True @@ -796,9 +790,7 @@ async def set_chk_take_subnet( ) return True, ext_id_ else: - print_error( - f"Unable to set childkey take. {message}" - ) + print_error(f"Unable to set childkey take. {message}") return False, ext_id_ # Print childkey take for other user and return (dont offer to change take rate) diff --git a/bittensor_cli/src/commands/stake/claim.py b/bittensor_cli/src/commands/stake/claim.py index ac57681c5..d07f4715b 100644 --- a/bittensor_cli/src/commands/stake/claim.py +++ b/bittensor_cli/src/commands/stake/claim.py @@ -436,9 +436,7 @@ def _prompt_claim_selection(claimable_stake: dict) -> Optional[list[int]]: else: selected = [int(netuid_input.strip())] except ValueError: - print_error( - "Invalid input. Please enter numbers only." - ) + print_error("Invalid input. Please enter numbers only.") continue if len(selected) > 5: @@ -448,16 +446,12 @@ def _prompt_claim_selection(claimable_stake: dict) -> Optional[list[int]]: continue if len(selected) == 0: - print_error( - "Please select at least one netuid." - ) + print_error("Please select at least one netuid.") continue invalid_netuids = [n for n in selected if n not in available_netuids] if invalid_netuids: - print_error( - f"Invalid netuids: {', '.join(map(str, invalid_netuids))}" - ) + print_error(f"Invalid netuids: {', '.join(map(str, invalid_netuids))}") continue selected = list(dict.fromkeys(selected)) @@ -670,9 +664,7 @@ async def _prompt_claim_netuids( ) except ValueError as e: - print_error( - f"Invalid subnet selection: {e}\nPlease try again." - ) + print_error(f"Invalid subnet selection: {e}\nPlease try again.") def _preview_subnet_selection( diff --git a/bittensor_cli/src/commands/subnets/subnets.py b/bittensor_cli/src/commands/subnets/subnets.py index 23199898a..ad0404b4f 100644 --- a/bittensor_cli/src/commands/subnets/subnets.py +++ b/bittensor_cli/src/commands/subnets/subnets.py @@ -280,9 +280,7 @@ async def _find_event_attributes_in_extrinsic_receipt( ) if not mev_success: status.stop() - print_error( - f"Failed: MEV execution failed: {mev_error}" - ) + print_error(f"Failed: MEV execution failed: {mev_error}") return False, None, None # Successful registration, final check for membership @@ -1091,9 +1089,7 @@ async def show_root(): return if len(root_state.hotkeys) == 0: - print_error( - "The root-subnet is currently empty with 0 UIDs registered." - ) + print_error("The root-subnet is currently empty with 0 UIDs registered.") return tao_sum = sum(root_state.tao_stake).tao @@ -1718,9 +1714,7 @@ async def burn_cost( ) ) else: - print_error( - "Subnet burn cost: Failed to get subnet burn cost" - ) + print_error("Subnet burn cost: Failed to get subnet burn cost") return None @@ -1999,9 +1993,7 @@ async def _storage_key(storage_fn: str) -> StorageKey: ) = [x[1] for x in storage_key_results] if not registration_allowed: - print_error( - f"Registration to subnet {netuid} is not allowed" - ) + print_error(f"Registration to subnet {netuid} is not allowed") if json_output: json_console.print_json( data={ diff --git a/bittensor_cli/src/commands/sudo.py b/bittensor_cli/src/commands/sudo.py index b92f31cdc..b039ea4f2 100644 --- a/bittensor_cli/src/commands/sudo.py +++ b/bittensor_cli/src/commands/sudo.py @@ -645,9 +645,7 @@ async def vote_senate_extrinsic( return True else: # hotkey not found in ayes/nays - print_error( - "Unknown error. Couldn't find vote." - ) + print_error("Unknown error. Couldn't find vote.") return False else: return False diff --git a/bittensor_cli/src/commands/wallets.py b/bittensor_cli/src/commands/wallets.py index 575520e3a..96c812be5 100644 --- a/bittensor_cli/src/commands/wallets.py +++ b/bittensor_cli/src/commands/wallets.py @@ -868,9 +868,7 @@ async def wallet_list( if wallet_name: wallets = [wallet for wallet in wallets if wallet.name == wallet_name] if not wallets: - print_error( - f"Wallet '{wallet_name}' not found in dir: {wallet_path}" - ) + print_error(f"Wallet '{wallet_name}' not found in dir: {wallet_path}") root = Tree("Wallets") main_data_dict = {"wallets": []} From bad7572e698ba308ec96a85665ab7a5eb03cef8c Mon Sep 17 00:00:00 2001 From: leonace924 Date: Fri, 19 Dec 2025 10:29:32 -0500 Subject: [PATCH 8/9] fix: update the unit test err_console --- tests/unit_tests/test_subnets_register.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/test_subnets_register.py b/tests/unit_tests/test_subnets_register.py index 0e4c6c962..0d4fd6789 100644 --- a/tests/unit_tests/test_subnets_register.py +++ b/tests/unit_tests/test_subnets_register.py @@ -90,7 +90,7 @@ async def test_register_subnet_does_not_exist( mock_subtensor_base.subnet_exists = AsyncMock(return_value=False) with patch( - "bittensor_cli.src.commands.subnets.subnets.err_console" + "bittensor_cli.src.bittensor.utils.err_console" ) as mock_err_console: result = await register( wallet=mock_wallet, From 5ad7b24d8f069c75d4fd032f0b8ca6d4f1a1b415 Mon Sep 17 00:00:00 2001 From: leonace924 Date: Fri, 19 Dec 2025 10:35:23 -0500 Subject: [PATCH 9/9] ruff --- tests/unit_tests/test_subnets_register.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/unit_tests/test_subnets_register.py b/tests/unit_tests/test_subnets_register.py index 0d4fd6789..854374c2d 100644 --- a/tests/unit_tests/test_subnets_register.py +++ b/tests/unit_tests/test_subnets_register.py @@ -89,9 +89,7 @@ async def test_register_subnet_does_not_exist( """Test registration fails when subnet does not exist.""" mock_subtensor_base.subnet_exists = AsyncMock(return_value=False) - with patch( - "bittensor_cli.src.bittensor.utils.err_console" - ) as mock_err_console: + with patch("bittensor_cli.src.bittensor.utils.err_console") as mock_err_console: result = await register( wallet=mock_wallet, subtensor=mock_subtensor_base,