From 286980880638b241a00916c98f16ba98b9ef7c0b Mon Sep 17 00:00:00 2001 From: bdhimes Date: Mon, 8 Sep 2025 21:05:29 +0200 Subject: [PATCH 1/4] Adds parent path creation for debug log. --- bittensor_cli/cli.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 0f35f1253..7ce8bbc80 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -612,7 +612,12 @@ def debug_callback(value: bool): "Enter the file location to save the debug log for the previous command.", default="~/.bittensor/debug-export", ).strip() - save_file_loc = os.path.expanduser(save_file_loc_) + save_file_loc = Path(os.path.expanduser(save_file_loc_)) + if not save_file_loc.parent.exists(): + if Confirm.ask( + f"The directory '{save_file_loc.parent}' does not exist. Would you like to create it?" + ): + save_file_loc.parent.mkdir(parents=True, exist_ok=True) try: with ( open(save_file_loc, "w+") as save_file, From b4560e1cff999a60384d9cd6bd220fa8cd74793f Mon Sep 17 00:00:00 2001 From: bdhimes Date: Mon, 8 Sep 2025 21:17:14 +0200 Subject: [PATCH 2/4] Error handling --- bittensor_cli/cli.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 7ce8bbc80..1f89a77cc 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -608,6 +608,18 @@ def commands_callback(value: bool): def debug_callback(value: bool): if value: + debug_file_loc = Path( + os.getenv("BTCLI_DEBUG_FILE") + or os.path.expanduser(defaults.config.debug_file_path) + ) + if not debug_file_loc.exists(): + print_error( + f"The debug file '{debug_file_loc}' does not exist. This indicates that you have not run a command " + f"which has logged debug output, or you deleted this file. If the debug file was created using the " + f"BTCLI_DEBUG_FILE environment variable, please set the value for the same location, and re-run " + f"this `btcli --debug` command." + ) + raise typer.Exit() save_file_loc_ = Prompt.ask( "Enter the file location to save the debug log for the previous command.", default="~/.bittensor/debug-export", @@ -621,16 +633,12 @@ def debug_callback(value: bool): try: with ( open(save_file_loc, "w+") as save_file, - open( - os.getenv("BTCLI_DEBUG_FILE") - or os.path.expanduser(defaults.config.debug_file_path), - "r", - ) as current_file, + open(debug_file_loc, "r") as current_file, ): save_file.write(current_file.read()) console.print(f"Saved debug log to {save_file_loc}") - except FileNotFoundError: - print_error(f"The filepath '{save_file_loc}' does not exist.") + except FileNotFoundError as e: + print_error(str(e)) raise typer.Exit() From 6ec1ad3ff966c8cea770aa3ce680611d316b3e16 Mon Sep 17 00:00:00 2001 From: bdhimes Date: Mon, 8 Sep 2025 21:31:59 +0200 Subject: [PATCH 3/4] Update error message --- bittensor_cli/cli.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 1f89a77cc..4275cd154 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -613,11 +613,12 @@ def debug_callback(value: bool): or os.path.expanduser(defaults.config.debug_file_path) ) if not debug_file_loc.exists(): - print_error( - f"The debug file '{debug_file_loc}' does not exist. This indicates that you have not run a command " - f"which has logged debug output, or you deleted this file. If the debug file was created using the " - f"BTCLI_DEBUG_FILE environment variable, please set the value for the same location, and re-run " - f"this `btcli --debug` command." + err_console.print( + f"[red]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]" ) raise typer.Exit() save_file_loc_ = Prompt.ask( From 52f58fb08190feb73bb3aba074fc39d0b36d335b Mon Sep 17 00:00:00 2001 From: bdhimes Date: Mon, 8 Sep 2025 21:48:02 +0200 Subject: [PATCH 4/4] Ensure that bool config items are bool. --- bittensor_cli/cli.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 4275cd154..88ae40580 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -1257,7 +1257,7 @@ def main_callback( ): """ Command line interface (CLI) for Bittensor. Uses the values in the configuration file. These values can be - overriden by passing them explicitly in the command line. + overridden by passing them explicitly in the command line. """ # Load or create the config file if os.path.exists(self.config_path): @@ -1281,6 +1281,9 @@ def main_callback( if sub_key not in config[key]: config[key][sub_key] = sub_value updated = True + elif isinstance(value, bool) and config[key] is None: + config[key] = value + updated = True if updated: with open(self.config_path, "w") as f: safe_dump(config, f)