diff --git a/src/Microsoft.Sbom.Api/Entities/ErrorType.cs b/src/Microsoft.Sbom.Api/Entities/ErrorType.cs index 39114a33..7d05e88b 100644 --- a/src/Microsoft.Sbom.Api/Entities/ErrorType.cs +++ b/src/Microsoft.Sbom.Api/Entities/ErrorType.cs @@ -47,5 +47,8 @@ public enum ErrorType NoPackagesFound = 11, [EnumMember(Value = "Manifest file signing error")] - ManifestFileSigningError = 12 + ManifestFileSigningError = 12, + + [EnumMember(Value = "Invalid input file")] + InvalidInputFile = 13 } diff --git a/src/Microsoft.Sbom.Api/Executors/EnumeratorChannel.cs b/src/Microsoft.Sbom.Api/Executors/EnumeratorChannel.cs index a09e580f..dd4db11c 100644 --- a/src/Microsoft.Sbom.Api/Executors/EnumeratorChannel.cs +++ b/src/Microsoft.Sbom.Api/Executors/EnumeratorChannel.cs @@ -6,6 +6,8 @@ using System.Threading.Channels; using System.Threading.Tasks; using Microsoft.Sbom.Api.Entities; +using Microsoft.Sbom.Api.Output.Telemetry; +using Microsoft.Sbom.JsonAsynchronousNodeKit.Exceptions; using Serilog; namespace Microsoft.Sbom.Api.Executors; @@ -42,6 +44,15 @@ async Task Enumerate() await output.Writer.WriteAsync(value); } } + catch (ParserException e) + { + // Don't log this here, as it will be logged by upstream error handling. + await errors.Writer.WriteAsync(new FileValidationResult + { + ErrorType = ErrorType.InvalidInputFile, + Path = e.Message + }); + } catch (Exception e) { log.Warning($"Encountered an unknown error while enumerating: {e.Message}"); diff --git a/src/Microsoft.Sbom.Api/Workflows/SBOMParserBasedValidationWorkflow.cs b/src/Microsoft.Sbom.Api/Workflows/SBOMParserBasedValidationWorkflow.cs index 9692a3af..f0b47beb 100644 --- a/src/Microsoft.Sbom.Api/Workflows/SBOMParserBasedValidationWorkflow.cs +++ b/src/Microsoft.Sbom.Api/Workflows/SBOMParserBasedValidationWorkflow.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; @@ -109,6 +110,12 @@ public async Task RunAsync() { case FilesResult filesResult: (successfullyValidatedFiles, fileValidationFailures) = await filesValidator.Validate(filesResult.Files); + var invalidInputFiles = fileValidationFailures.Where(f => f.ErrorType == ErrorType.InvalidInputFile).ToList(); + if (invalidInputFiles.Count != 0) + { + throw new InvalidDataException($"Your manifest file is malformed. {invalidInputFiles.First().Path}"); + } + break; case PackagesResult packagesResult: var packages = packagesResult.Packages.ToList();