diff --git a/tools/dotnet-linker/Steps/ConfigurationAwareStep.cs b/tools/dotnet-linker/Steps/ConfigurationAwareStep.cs index 8961aae671..86ac39e656 100644 --- a/tools/dotnet-linker/Steps/ConfigurationAwareStep.cs +++ b/tools/dotnet-linker/Steps/ConfigurationAwareStep.cs @@ -16,9 +16,9 @@ namespace Xamarin.Linker { get { return LinkerConfiguration.GetInstance (Context); } } - protected void Report (Exception exception) + protected void Report (params Exception [] exceptions) { - Report (new Exception[] { exceptions }); + Report ((IList) exceptions); } protected void Report (IList? exceptions) @@ -50,7 +50,8 @@ namespace Xamarin.Linker { protected sealed override void EndProcess () { try { - TryEndProcess (); + TryEndProcess (out var exceptions); + Report (exceptions); } catch (Exception e) { Report (FailEnd (e)); } @@ -69,6 +70,12 @@ namespace Xamarin.Linker { { } + protected virtual void TryEndProcess (out List? exceptions) + { + exceptions = null; + TryEndProcess (); + } + // failure overrides, with defaults bool CollectProductExceptions (Exception e, [NotNullWhen (true)] out List? productExceptions) @@ -88,22 +95,22 @@ namespace Xamarin.Linker { return false; } - protected virtual Exception Fail (AssemblyDefinition assembly, Exception e) + protected virtual Exception [] Fail (AssemblyDefinition assembly, Exception e) { return CollectExceptions (e, () => ErrorHelper.CreateError (ErrorCode, Errors.MX_ConfigurationAwareStepWithAssembly, Name, assembly?.FullName, e.Message)); } - protected virtual Exception Fail (Exception e) + protected virtual Exception [] Fail (Exception e) { return CollectExceptions (e, () => ErrorHelper.CreateError (ErrorCode | 1, Errors.MX_ConfigurationAwareStep, Name, e.Message)); } - protected virtual Exception FailEnd (Exception e) + protected virtual Exception [] FailEnd (Exception e) { return CollectExceptions (e, () => ErrorHelper.CreateError (ErrorCode | 2, Errors.MX_ConfigurationAwareStep, Name, e.Message)); } - Exception CollectExceptions (Exception e, Func createException) + Exception [] CollectExceptions (Exception e, Func createException) { // Detect if we're reporting one or more ProductExceptions (and no other exceptions), and in that case // report the product exceptions as top-level exceptions + the step-specific exception at the end, @@ -117,10 +124,10 @@ namespace Xamarin.Linker { // instead return an aggregate exception with the original exception and all the ProductExceptions we're reporting. productExceptions.Add (ex); } - return new AggregateException (productExceptions); + return productExceptions.ToArray (); } - return createException (); + return new Exception [] { createException () }; } // abstracts