diff --git a/circfirm/cli.py b/circfirm/cli.py index b2f4ba1..266b914 100644 --- a/circfirm/cli.py +++ b/circfirm/cli.py @@ -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") diff --git a/tests/test_cli.py b/tests/test_cli.py index 4fb6c0a..2b78242 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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])