From 8f6a8ea8b2271cb299351e08450b7646557efc9c Mon Sep 17 00:00:00 2001 From: CartBlanche Date: Fri, 19 Jul 2024 17:20:01 +0100 Subject: [PATCH] Fix edge case where passed in configuration doesn't exist in app path. --- .../Commands/Current/App/AppTools.cs | 21 +++++++++++++------ Source/v2/Meadow.Cli/Strings.cs | 5 +++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Source/v2/Meadow.CLI/Commands/Current/App/AppTools.cs b/Source/v2/Meadow.CLI/Commands/Current/App/AppTools.cs index 00635783..59435a9a 100644 --- a/Source/v2/Meadow.CLI/Commands/Current/App/AppTools.cs +++ b/Source/v2/Meadow.CLI/Commands/Current/App/AppTools.cs @@ -63,16 +63,25 @@ internal static async Task TrimApplication(string path, if (configuration is not null) { - file = candidates - .Where(c => c.DirectoryName.IndexOf(configuration, StringComparison.OrdinalIgnoreCase) >= 0) - .OrderByDescending(c => c.LastWriteTime) - .First(); + var foundConfiguration = candidates.Where(c => c.DirectoryName?.IndexOf(configuration, StringComparison.OrdinalIgnoreCase) >= 0); - if (file == null) + if (foundConfiguration.Count() == 0) { - logger?.LogError($"{Strings.NoCompiledApplicationFound} at '{path}'"); + logger?.LogError($"{Strings.NoCompiledApplicationFound} {Strings.WithConfiguration} '{configuration}' {Strings.At} '{path}'"); return false; } + else + { + file = foundConfiguration + .OrderByDescending(c => c.LastWriteTime) + .First(); + + if (file == null) + { + logger?.LogError($"{Strings.NoCompiledApplicationFound} {Strings.At} '{path}'"); + return false; + } + } } else { diff --git a/Source/v2/Meadow.Cli/Strings.cs b/Source/v2/Meadow.Cli/Strings.cs index f293eb27..4a0fb946 100644 --- a/Source/v2/Meadow.Cli/Strings.cs +++ b/Source/v2/Meadow.Cli/Strings.cs @@ -70,9 +70,10 @@ public static class Strings public const string AppDeployFailed = "Application deploy failed"; public const string AppDeployedSuccessfully = "Application deployed successfully"; public const string AppTrimFailed = "Application trimming failed"; + public const string WithConfiguration = "with configuration"; + public const string At = "at"; - - public static class Telemetry + public static class Telemetry { public const string ConsentMessage = @$" Let's improve the Meadow experience together