Skip to content

Commit b4560e1

Browse files
committed
Error handling
1 parent 2869808 commit b4560e1

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

bittensor_cli/cli.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,18 @@ def commands_callback(value: bool):
608608

609609
def debug_callback(value: bool):
610610
if value:
611+
debug_file_loc = Path(
612+
os.getenv("BTCLI_DEBUG_FILE")
613+
or os.path.expanduser(defaults.config.debug_file_path)
614+
)
615+
if not debug_file_loc.exists():
616+
print_error(
617+
f"The debug file '{debug_file_loc}' does not exist. This indicates that you have not run a command "
618+
f"which has logged debug output, or you deleted this file. If the debug file was created using the "
619+
f"BTCLI_DEBUG_FILE environment variable, please set the value for the same location, and re-run "
620+
f"this `btcli --debug` command."
621+
)
622+
raise typer.Exit()
611623
save_file_loc_ = Prompt.ask(
612624
"Enter the file location to save the debug log for the previous command.",
613625
default="~/.bittensor/debug-export",
@@ -621,16 +633,12 @@ def debug_callback(value: bool):
621633
try:
622634
with (
623635
open(save_file_loc, "w+") as save_file,
624-
open(
625-
os.getenv("BTCLI_DEBUG_FILE")
626-
or os.path.expanduser(defaults.config.debug_file_path),
627-
"r",
628-
) as current_file,
636+
open(debug_file_loc, "r") as current_file,
629637
):
630638
save_file.write(current_file.read())
631639
console.print(f"Saved debug log to {save_file_loc}")
632-
except FileNotFoundError:
633-
print_error(f"The filepath '{save_file_loc}' does not exist.")
640+
except FileNotFoundError as e:
641+
print_error(str(e))
634642
raise typer.Exit()
635643

636644

0 commit comments

Comments
 (0)