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 28d47a4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
15 changes: 10 additions & 5 deletions circfirm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,16 @@ def install(version: str, language: str, board: Optional[str]) -> None:
sys.exit(2)

if not circfirm.backend.is_downloaded(board, version, language):
announce_and_await(
"Downloading UF2",
circfirm.backend.download_uf2,
args=(board, version, language),
)
try:
announce_and_await(
"Downloading UF2",
circfirm.backend.download_uf2,
args=(board, version, language),
)
except ConnectionError as err:
click.echo(" failed") # Mark as failed
click.echo(f"Error: {err.args[0]}")
sys.exit(4)
else:
click.echo(f"Using cached firmware file")

Expand Down
36 changes: 19 additions & 17 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,25 @@ def wait_and_add() -> None:
ERR_NOT_FOUND = 1
ERR_FOUND_CIRCUITPY = 2
ERR_IN_BOOTLOADER = 3
try:
# Test not finding the mounted drive
tests.helpers.delete_mount_node(circfirm.UF2INFO_FILE)
result = runner.invoke(
cli, ["install", version, "--board", "feather_m4_express"]
)
assert result.exit_code == ERR_NOT_FOUND

# Test finding the mounted drive as CIRCUITPY
tests.helpers.copy_boot_out()
result = runner.invoke(
cli, ["install", version, "--board", "feather_m4_express"]
)
assert result.exit_code == ERR_FOUND_CIRCUITPY
tests.helpers.delete_mount_node(circfirm.BOOTOUT_FILE)
finally:
tests.helpers.copy_uf2_info()
ERR_UF2_DOWNLOAD = 4

# Test not finding the mounted drive
tests.helpers.delete_mount_node(circfirm.UF2INFO_FILE)
result = runner.invoke(cli, ["install", version, "--board", "feather_m4_express"])
assert result.exit_code == ERR_NOT_FOUND

# Test finding the mounted drive as CIRCUITPY
tests.helpers.copy_boot_out()
result = runner.invoke(cli, ["install", version, "--board", "feather_m4_express"])
assert result.exit_code == ERR_FOUND_CIRCUITPY

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

# Test using install when in bootloader mode
result = runner.invoke(cli, ["install", version])
Expand Down

0 comments on commit 28d47a4

Please sign in to comment.