Skip to content

Commit

Permalink
Improve response messages if UF2 download fails during install command
Browse files Browse the repository at this point in the history
  • Loading branch information
tekktrik committed Feb 23, 2024
1 parent b44e991 commit 552fee9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 9 additions & 4 deletions circfirm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@ def install(version: str, language: str, board: Optional[str]) -> None:
uf2file = circfirm.backend.get_uf2_filepath(board, version, language)
uf2filename = os.path.basename(uf2file)
uf2_path = os.path.join(bootloader, uf2filename)
announce_and_await(
f"Copying UF2 to {board}", shutil.copyfile, args=(uf2file, uf2_path)
)
click.echo("Device should reboot momentarily.")
try:
announce_and_await(
f"Copying UF2 to {board}", shutil.copyfile, args=(uf2file, uf2_path)
)
click.echo("Device should reboot momentarily.")
except ConnectionError as err:
click.echo(" failed") # Mark as failed
click.echo(f"Error: {err.args[0]}")
sys.exit(4)


@cli.group()
Expand Down
8 changes: 8 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def wait_and_add() -> None:
ERR_NOT_FOUND = 1
ERR_FOUND_CIRCUITPY = 2
ERR_IN_BOOTLOADER = 3
ERR_UF2_DOWNLOAD = 4
try:
# Test not finding the mounted drive
tests.helpers.delete_mount_node(circfirm.UF2INFO_FILE)
Expand All @@ -62,6 +63,13 @@ def wait_and_add() -> None:
cli, ["install", version, "--board", "feather_m4_express"]
)
assert result.exit_code == ERR_FOUND_CIRCUITPY

# Test using bad board version
tests.helpers.copy_boot_out()
result = runner.invoke(
cli, ["install", "doesnotexist", "--board", "feather_m4_express"]
)
assert result.exit_code == ERR_UF2_DOWNLOAD
tests.helpers.delete_mount_node(circfirm.BOOTOUT_FILE)
finally:
tests.helpers.copy_uf2_info()
Expand Down

0 comments on commit 552fee9

Please sign in to comment.