diff --git a/circfirm/cli.py b/circfirm/cli.py index b2f4ba1..986aa71 100644 --- a/circfirm/cli.py +++ b/circfirm/cli.py @@ -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() diff --git a/tests/test_cli.py b/tests/test_cli.py index 4fb6c0a..3e3781e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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) @@ -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()