Skip to content

Commit

Permalink
Trap the whole deserliaization for better error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
CartBlanche committed Jul 30, 2024
1 parent 5f1a88a commit b82fb4b
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions Source/v2/Meadow.CLI/Commands/Current/Provision/ProvisionCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Threading.Tasks;
using CliFx.Attributes;
using Meadow.CLI.Commands.DeviceManagement;
Expand Down Expand Up @@ -104,7 +105,6 @@ protected override async ValueTask ExecuteCommand()
{
deployApp = false;
AnsiConsole.MarkupLine($"[red]{Strings.Provision.FileNotFound}[/]", $"[yellow]{path}[/]");
AnsiConsole.MarkupLine(Strings.Provision.NoAppDeployment, $"[yellow]{OsVersion}[/]");
}
else
{
Expand All @@ -113,42 +113,42 @@ protected override async ValueTask ExecuteCommand()

if (deployApp)
{
var provisionSettings = JsonConvert.DeserializeObject<ProvisionSettings>(File.ReadAllText(Path!));
if (provisionSettings == null)
{
throw new Exception("Failed to read provision.json file.");
}

// Use the settings from provisionSettings as needed
try
{
var provisionSettings = JsonConvert.DeserializeObject<ProvisionSettings>(await File.ReadAllTextAsync(Path!));
if (provisionSettings == null)
{
throw new Exception("Failed to read provision.json file.");
}

// Use the settings from provisionSettings as needed
configuration = provisionSettings.Configuration;
OsVersion = provisionSettings.OsVersion;

appPath = AppTools.ValidateAndSanitizeAppPath(provisionSettings.AppPath);

if (!File.Exists(appPath))
{
throw new FileNotFoundException($"App.dll Not found at location:{appPath}");
}

configuration = provisionSettings.Configuration;
OsVersion = provisionSettings.OsVersion;

AnsiConsole.MarkupLine(Strings.Provision.TrimmingApp);
await AppTools.TrimApplication(appPath!, packageManager, OsVersion!, configuration, null, null, Console, CancellationToken);
}
catch (Exception ex)
{
// Eat the exception and keep going.
deployApp = false;
// TODO put this back in for release #if DEBUG
var message = ex.Message;
var stackTrace = ex.StackTrace;
message += Environment.NewLine + stackTrace;
AnsiConsole.MarkupLine($"[red]{ex.Message}[/]");
//#endif
AnsiConsole.MarkupLine(Strings.Provision.NoAppDeployment, $"[yellow]{OsVersion}[/]");
Debug.WriteLine($"{ex.Message + Environment.NewLine + ex.StackTrace}");
}
}

if(!deployApp)
{
AnsiConsole.MarkupLine(Strings.Provision.NoAppDeployment, $"[yellow]{OsVersion}[/]");
}

if (string.IsNullOrEmpty(OsVersion))
{
OsVersion = DefaultOSVersion;
Expand Down

0 comments on commit b82fb4b

Please sign in to comment.