|
1 | 1 | using System; |
2 | 2 | using System.IO.Abstractions; |
| 3 | +using System.Linq; |
3 | 4 | using System.Threading.Tasks; |
4 | 5 | using AET.ModVerify.App.GameFinder; |
5 | 6 | using AET.ModVerify.App.Reporting; |
|
9 | 10 | using AET.ModVerify.Reporting.Baseline; |
10 | 11 | using AET.ModVerify.Reporting.Suppressions; |
11 | 12 | using AnakinRaW.ApplicationBase; |
| 13 | +using AnakinRaW.CommonUtilities.SimplePipeline; |
12 | 14 | using Microsoft.Extensions.DependencyInjection; |
13 | 15 | using Microsoft.Extensions.Logging; |
14 | 16 |
|
@@ -74,9 +76,34 @@ public async Task<int> ExecuteAsync() |
74 | 76 | var verificationResult = await VerifyTargetAsync(verificationTarget) |
75 | 77 | .ConfigureAwait(false); |
76 | 78 |
|
| 79 | + Console.WriteLine(); |
| 80 | + |
| 81 | + switch (verificationResult.Status) |
| 82 | + { |
| 83 | + case VerificationCompletionStatus.Cancelled: |
| 84 | + return ModVerifyConstants.VerifyCancelled; |
| 85 | + case VerificationCompletionStatus.Failed: |
| 86 | + return ReportVerificationFailure(verificationResult.Exception!); |
| 87 | + } |
| 88 | + |
77 | 89 | return await ProcessResult(verificationResult); |
78 | 90 | } |
79 | 91 |
|
| 92 | + private int ReportVerificationFailure(Exception verificationException) |
| 93 | + { |
| 94 | + var exceptionToReport = verificationException switch |
| 95 | + { |
| 96 | + AggregateException aggregate => aggregate.InnerExceptions.FirstOrDefault() ?? aggregate, |
| 97 | + StepFailureException stepFailure => stepFailure.FailedSteps.First().Error!, |
| 98 | + _ => verificationException |
| 99 | + }; |
| 100 | + |
| 101 | + ConsoleUtilities.WriteApplicationFatalError(_appEnvironment.ApplicationName, exceptionToReport); |
| 102 | + Logger?.LogError(exceptionToReport, exceptionToReport.Message); |
| 103 | + |
| 104 | + return exceptionToReport.HResult; |
| 105 | + } |
| 106 | + |
80 | 107 | protected abstract Task<int> ProcessResult(VerificationResult result); |
81 | 108 |
|
82 | 109 | protected abstract VerificationBaseline GetBaseline(VerificationTarget verificationTarget); |
@@ -112,6 +139,10 @@ private async Task<VerificationResult> VerifyTargetAsync(VerificationTarget veri |
112 | 139 | case VerificationCompletionStatus.Cancelled: |
113 | 140 | Logger?.LogWarning(ModVerifyConstants.ConsoleEventId, "Verification was cancelled."); |
114 | 141 | break; |
| 142 | + case VerificationCompletionStatus.Failed: |
| 143 | + progressReporter.ReportError("Verification failed!", |
| 144 | + $"An unexpected error occurred while verifying '{verificationTarget.Name}'."); |
| 145 | + break; |
115 | 146 | case VerificationCompletionStatus.Completed: |
116 | 147 | default: |
117 | 148 | Logger?.LogInformation(ModVerifyConstants.ConsoleEventId, "Verification completed successfully."); |
|
0 commit comments