Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,7 @@ def _run_command(self, cmd: Coroutine, exit_early: bool = True):

async def _run():
initiated = False
exception_occurred = False
try:
if self.subtensor:
await self.subtensor.substrate.initialize()
Expand All @@ -1311,6 +1312,7 @@ async def _run():
except (ConnectionRefusedError, ssl.SSLError, InvalidHandshake):
err_console.print(f"Unable to connect to the chain: {self.subtensor}")
verbose_console.print(traceback.format_exc())
exception_occurred = True
except (
ConnectionClosed,
SubstrateRequestException,
Expand All @@ -1322,22 +1324,25 @@ async def _run():
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}")
verbose_console.print(traceback.format_exc())
exception_occurred = True
finally:
if initiated is False:
asyncio.create_task(cmd).cancel()
if (
exit_early is True
): # temporarily to handle multiple run commands in one session
try:
if self.subtensor:
if self.subtensor:
try:
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}")
if exception_occurred:
raise typer.Exit()
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}")

return self.event_loop.run_until_complete(_run())

Expand Down
2 changes: 1 addition & 1 deletion bittensor_cli/src/bittensor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,7 @@ async def print_extrinsic_id(
Args:
extrinsic_receipt: AsyncExtrinsicReceipt object from a successful extrinsic submission.
"""
if extrinsic_receipt is None:
if extrinsic_receipt is None or not (await extrinsic_receipt.is_success):
return
substrate = extrinsic_receipt.substrate
ext_id = await extrinsic_receipt.get_extrinsic_identifier()
Expand Down
8 changes: 3 additions & 5 deletions bittensor_cli/src/commands/stake/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,6 @@ async def move_stake(
response = await subtensor.substrate.submit_extrinsic(
extrinsic, wait_for_inclusion=True, wait_for_finalization=False
)
await print_extrinsic_id(response)
ext_id = await response.get_extrinsic_identifier()

if not prompt:
Expand All @@ -580,6 +579,7 @@ async def move_stake(
)
return False, ""
else:
await print_extrinsic_id(response)
console.print(
":white_heavy_check_mark: [dark_sea_green3]Stake moved.[/dark_sea_green3]"
)
Expand Down Expand Up @@ -755,7 +755,6 @@ async def transfer_stake(
extrinsic, wait_for_inclusion=True, wait_for_finalization=False
)
ext_id = await response.get_extrinsic_identifier()
await print_extrinsic_id(extrinsic)

if not prompt:
console.print(":white_heavy_check_mark: [green]Sent[/green]")
Expand All @@ -767,7 +766,7 @@ async def transfer_stake(
f"{format_error_message(await response.error_message)}"
)
return False, ""

await print_extrinsic_id(extrinsic)
# Get and display new stake balances
new_stake, new_dest_stake = await asyncio.gather(
subtensor.get_stake(
Expand Down Expand Up @@ -933,7 +932,6 @@ async def swap_stake(
wait_for_finalization=wait_for_finalization,
)
ext_id = await response.get_extrinsic_identifier()
await print_extrinsic_id(response)

if not prompt:
console.print(":white_heavy_check_mark: [green]Sent[/green]")
Expand All @@ -945,7 +943,7 @@ async def swap_stake(
f"{format_error_message(await response.error_message)}"
)
return False, ""

await print_extrinsic_id(response)
# Get and display new stake balances
new_stake, new_dest_stake = await asyncio.gather(
subtensor.get_stake(
Expand Down
Loading