@@ -608,6 +608,18 @@ def commands_callback(value: bool):
608
608
609
609
def debug_callback (value : bool ):
610
610
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 ()
611
623
save_file_loc_ = Prompt .ask (
612
624
"Enter the file location to save the debug log for the previous command." ,
613
625
default = "~/.bittensor/debug-export" ,
@@ -621,16 +633,12 @@ def debug_callback(value: bool):
621
633
try :
622
634
with (
623
635
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 ,
629
637
):
630
638
save_file .write (current_file .read ())
631
639
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 ) )
634
642
raise typer .Exit ()
635
643
636
644
0 commit comments