Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,34 @@ public void AMissingAssemblyIsSkippedWhenContinuing() {
Check.That(result).IsEmpty();
}

[Fact(DisplayName = "A skipped assembly is logged as a warning (never silent) when the failure behavior is Continue.")]
public void ASkippedAssemblyIsLoggedWhenContinuing() {
// Setup
RecordingGenerationLogger logger = new();
SolutionGenerationOptions options = new() {
FailureBehavior = FailureBehavior.Continue,
Logger = logger
};

// Exercise
SolutionErrorDocumentationGenerator.GetErrorDocumentationFromAssemblies(new[] { "this-assembly-does-not-exist.dll" }, options);

// Verify: the skipped assembly leaves a warning trace mentioning the missing file.
Check.That(logger.Warnings).HasSize(1);
Check.That(logger.Warnings[0]).Contains("this-assembly-does-not-exist.dll");
}

private sealed class RecordingGenerationLogger : IGenerationLogger {

public List<string> Warnings { get; } = new();

public void Info(string message) { }
public void Warning(string message) { Warnings.Add(message); }
public void Error(string message) { }
public void Debug(string message) { }

}

[Fact(DisplayName = "A missing assembly aborts when the failure behavior is Stop.")]
public void AMissingAssemblyAbortsWhenStopping() {
// Setup
Expand Down
10 changes: 9 additions & 1 deletion FirstClassErrors.GenDoc/SolutionErrorDocumentationGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,15 @@ private static ProcessResult RunProcess(string fileName, string arguments, strin
}

private static void HandleFailure(SolutionGenerationOptions options, string message, Exception? ex = null) {
if (options.FailureBehavior == FailureBehavior.Continue) { return; }
if (options.FailureBehavior == FailureBehavior.Continue) {
// In Continue mode the failure is swallowed so the generation proceeds with the remaining assemblies, but it
// must never be silent: log it as a warning (with the exception detail when present) so the skipped assembly
// leaves a trace the caller can diagnose.
options.Logger.Warning(ex is not null ? $"{message} {ex}" : message);

return;
}

if (ex is not null) { throw new SolutionDocumentationGenerationException(message, ex); }

throw new SolutionDocumentationGenerationException(message);
Expand Down
Loading