Skip to content

Commit

Permalink
fix: Improve logging on a corrupted manifest file (#551)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveTryon authored Apr 15, 2024
1 parent dc4e2e0 commit c76868d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Microsoft.Sbom.Api/Entities/ErrorType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 11 additions & 0 deletions src/Microsoft.Sbom.Api/Executors/EnumeratorChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -109,6 +110,12 @@ public async Task<bool> 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();
Expand Down

0 comments on commit c76868d

Please sign in to comment.