diff --git a/src/WingetCreateCLI/Commands/NewCommand.cs b/src/WingetCreateCLI/Commands/NewCommand.cs index 63308980..f2478e58 100644 --- a/src/WingetCreateCLI/Commands/NewCommand.cs +++ b/src/WingetCreateCLI/Commands/NewCommand.cs @@ -18,6 +18,7 @@ namespace Microsoft.WingetCreateCLI.Commands using Microsoft.WingetCreateCLI.Telemetry.Events; using Microsoft.WingetCreateCore; using Microsoft.WingetCreateCore.Common; + using Microsoft.WingetCreateCore.Common.Exceptions; using Microsoft.WingetCreateCore.Models; using Microsoft.WingetCreateCore.Models.DefaultLocale; using Microsoft.WingetCreateCore.Models.Installer; @@ -110,18 +111,17 @@ public override async Task Execute() return false; } - if (!PackageParser.ParsePackages( - packageFiles, - this.InstallerUrls, - manifests, - out List detectedArchs)) + try { - Logger.ErrorLocalized(nameof(Resources.PackageParsing_Error)); + PackageParser.ParsePackages(packageFiles, this.InstallerUrls, manifests, out List detectedArchs); + DisplayMismatchedArchitectures(detectedArchs); + } + catch (ParsePackageException exception) + { + exception.ParseFailedInstallerUrls.ForEach(i => Logger.ErrorLocalized(nameof(Resources.PackageParsing_Error), i)); return false; } - DisplayMismatchedArchitectures(detectedArchs); - Console.WriteLine(Resources.NewCommand_Header); Console.WriteLine(); Logger.InfoLocalized(nameof(Resources.ManifestDocumentation_HelpText), ManifestDocumentationUrl); diff --git a/src/WingetCreateCore/Common/PackageParser.cs b/src/WingetCreateCore/Common/PackageParser.cs index 27d8842e..3951d956 100644 --- a/src/WingetCreateCore/Common/PackageParser.cs +++ b/src/WingetCreateCore/Common/PackageParser.cs @@ -82,8 +82,7 @@ public static void SetHttpMessageHandler(HttpMessageHandler httpMessageHandler) /// Installer urls. /// Wrapper object for manifest object models. /// List of DetectedArch objects that represent each installers detected architectures. - /// True if packages were successfully parsed and metadata extracted, false otherwise. - public static bool ParsePackages( + public static void ParsePackages( IEnumerable paths, IEnumerable urls, Manifests manifests, @@ -97,16 +96,20 @@ public static bool ParsePackages( InstallerManifest installerManifest = manifests.InstallerManifest = new InstallerManifest(); DefaultLocaleManifest defaultLocaleManifest = manifests.DefaultLocaleManifest = new DefaultLocaleManifest(); + List parseFailedInstallerUrls = new List(); foreach (var package in paths.Zip(urls, (path, url) => (path, url))) { if (!ParsePackage(package.path, package.url, manifests, ref detectedArchOfInstallers)) { - return false; + parseFailedInstallerUrls.Add(package.url); } } - return true; + if (parseFailedInstallerUrls.Any()) + { + throw new ParsePackageException(parseFailedInstallerUrls); + } } /// diff --git a/src/WingetCreateTests/WingetCreateTests/UnitTests/PackageParserTests.cs b/src/WingetCreateTests/WingetCreateTests/UnitTests/PackageParserTests.cs index 4562fe9e..978a5d3c 100644 --- a/src/WingetCreateTests/WingetCreateTests/UnitTests/PackageParserTests.cs +++ b/src/WingetCreateTests/WingetCreateTests/UnitTests/PackageParserTests.cs @@ -46,10 +46,8 @@ public void ParseExeInstallerFile() { var testExeInstallerPath = TestUtils.MockDownloadFile(TestConstants.TestExeInstaller); Assert.That(testExeInstallerPath, Is.Not.Null.And.Not.Empty); - Manifests manifests = new Manifests(); - - Assert.IsTrue(PackageParser.ParsePackages(new[] { testExeInstallerPath }, new[] { TestConstants.TestExeInstaller }, manifests, out _)); + Assert.DoesNotThrow(() => PackageParser.ParsePackages(new[] { testExeInstallerPath }, new[] { TestConstants.TestExeInstaller }, manifests, out _)); Assert.AreEqual("WingetCreateTestExeInstaller", manifests.DefaultLocaleManifest.PackageName); Assert.AreEqual("Microsoft Corporation", manifests.DefaultLocaleManifest.Publisher); Assert.AreEqual("MicrosoftCorporation.WingetCreateTestExeInstaller", manifests.VersionManifest.PackageIdentifier); @@ -65,10 +63,8 @@ public void ParseMsiInstallerFile() { var testMsiInstallerPath = TestUtils.MockDownloadFile(TestConstants.TestMsiInstaller); Assert.That(testMsiInstallerPath, Is.Not.Null.And.Not.Empty); - Manifests manifests = new Manifests(); - - Assert.IsTrue(PackageParser.ParsePackages(new[] { testMsiInstallerPath }, new[] { TestConstants.TestExeInstaller }, manifests, out _)); + Assert.DoesNotThrow(() => PackageParser.ParsePackages(new[] { testMsiInstallerPath }, new[] { TestConstants.TestExeInstaller }, manifests, out _)); Assert.AreEqual("WingetCreateTestMsiInstaller", manifests.DefaultLocaleManifest.PackageName); Assert.AreEqual("Microsoft Corporation", manifests.DefaultLocaleManifest.Publisher); Assert.AreEqual("MicrosoftCorporation.WingetCreateTestMsiInstaller", manifests.VersionManifest.PackageIdentifier); @@ -84,10 +80,8 @@ public void ParseMsixInstallerFile() { var testMsixInstallerPath = TestUtils.MockDownloadFile(TestConstants.TestMsixInstaller); Assert.That(testMsixInstallerPath, Is.Not.Null.And.Not.Empty); - Manifests manifests = new Manifests(); - - Assert.IsTrue(PackageParser.ParsePackages(new[] { testMsixInstallerPath }, new[] { TestConstants.TestMsixInstaller }, manifests, out _)); + Assert.DoesNotThrow(() => PackageParser.ParsePackages(new[] { testMsixInstallerPath }, new[] { TestConstants.TestMsixInstaller }, manifests, out _)); Assert.AreEqual("WingetCreateTestMsixInstaller", manifests.DefaultLocaleManifest.PackageName); Assert.AreEqual("Microsoft Corporation", manifests.DefaultLocaleManifest.Publisher); Assert.AreEqual("1.0.1.0", manifests.VersionManifest.PackageVersion); @@ -108,10 +102,8 @@ public void ParseMultipleInstallers() Assert.That(testExeInstallerPath, Is.Not.Null.And.Not.Empty); var testMsixInstallerPath = TestUtils.MockDownloadFile(TestConstants.TestMsixInstaller); Assert.That(testMsixInstallerPath, Is.Not.Null.And.Not.Empty); - Manifests manifests = new Manifests(); - - Assert.IsTrue(PackageParser.ParsePackages( + Assert.DoesNotThrow(() => PackageParser.ParsePackages( new[] { testExeInstallerPath, testMsiInstallerPath, testMsixInstallerPath }, new[] { TestConstants.TestExeInstaller, TestConstants.TestMsiInstaller, TestConstants.TestMsixInstaller }, manifests,