From b558e6ca8b0422a9794de34cf585918a762357f5 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Sat, 17 Feb 2024 14:08:17 -0800 Subject: [PATCH] Return command exceptions to improve user feedback --- .../Current/Firmware/FirmwareWriteCommand.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs index a5576332..8219755a 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs @@ -4,6 +4,7 @@ using Meadow.LibUsb; using Meadow.Software; using Microsoft.Extensions.Logging; +using System.IO; namespace Meadow.CLI.Commands.DeviceManagement; @@ -130,7 +131,7 @@ protected override async ValueTask ExecuteCommand() var fullPath = Path.GetFullPath(IndividualFile); if (!File.Exists(fullPath)) { - throw new FileNotFoundException(fullPath); + throw new CommandException($"Invalid firmware path {fullPath}", CommandExitCode.FileNotFound); } // set the file type @@ -142,7 +143,7 @@ protected override async ValueTask ExecuteCommand() F7FirmwarePackageCollection.F7FirmwareFiles.CoprocApplicationFile => new[] { FirmwareType.ESP }, F7FirmwarePackageCollection.F7FirmwareFiles.CoprocBootloaderFile => new[] { FirmwareType.ESP }, F7FirmwarePackageCollection.F7FirmwareFiles.CoprocPartitionTableFile => new[] { FirmwareType.ESP }, - _ => throw new ArgumentException($"Unknown firmware file {Path.GetFileName(IndividualFile)}") + _ => throw new CommandException($"Unknown firmware file {Path.GetFileName(IndividualFile)}") }; Logger?.LogInformation($"Writing firmware file '{fullPath}'..."); @@ -364,7 +365,7 @@ private async Task WriteEspFiles(IMeadowConnection? connection, DeviceInfo? devi { 0 => null, 1 => devices[0], - _ => throw new Exception("Multiple devices found in bootloader mode - only connect one device"), + _ => throw new CommandException("Multiple devices found in bootloader mode - only connect one device"), }; } @@ -389,8 +390,7 @@ private async Task WriteEspFiles(IMeadowConnection? connection, DeviceInfo? devi } else { - Version = collection.DefaultPackage?.Version ?? - throw new Exception("No default version set"); + Version = collection.DefaultPackage?.Version ?? throw new CommandException("No default version set"); package = collection.DefaultPackage; } @@ -463,7 +463,7 @@ await DfuUtils.FlashFile( { if (retryCount++ > 10) { - throw new Exception("New meadow device not found"); + throw new CommandException("New meadow device not found"); } await Task.Delay(500); ports = await MeadowConnectionManager.GetSerialPorts();