Skip to content

Commit

Permalink
Merge pull request #481 from WildernessLabs/firmware_write_returns
Browse files Browse the repository at this point in the history
Return command exceptions to improve user feedback
  • Loading branch information
adrianstevens committed Feb 17, 2024
2 parents 447edab + b558e6c commit 979f9c9
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Meadow.LibUsb;
using Meadow.Software;
using Microsoft.Extensions.Logging;
using System.IO;

namespace Meadow.CLI.Commands.DeviceManagement;

Expand Down Expand Up @@ -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
Expand All @@ -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}'...");
Expand Down Expand Up @@ -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"),
};
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 979f9c9

Please sign in to comment.