stop rewriting module at first error

This commit is contained in:
Jesse Plamondon-Willard 2020-06-03 18:58:04 -04:00
parent 8c4edc2765
commit 80f882baf3
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
1 changed files with 6 additions and 0 deletions

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Threading;
using Mono.Cecil; using Mono.Cecil;
using Mono.Cecil.Cil; using Mono.Cecil.Cil;
using Mono.Collections.Generic; using Mono.Collections.Generic;
@ -59,6 +60,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Framework
{ {
// rewrite each type in the assembly, tracking whether any type was rewritten (Item1) // rewrite each type in the assembly, tracking whether any type was rewritten (Item1)
// and any exception that occurred during rewriting (Item2). // and any exception that occurred during rewriting (Item2).
var cancellationToken = new CancellationTokenSource();
Tuple<bool, Exception> result = this.Module Tuple<bool, Exception> result = this.Module
.GetTypes() .GetTypes()
.Where(type => type.BaseType != null) // skip special types like <Module> .Where(type => type.BaseType != null) // skip special types like <Module>
@ -66,6 +68,9 @@ namespace StardewModdingAPI.Framework.ModLoading.Framework
.WithExecutionMode(ParallelExecutionMode.ForceParallelism) .WithExecutionMode(ParallelExecutionMode.ForceParallelism)
.Select(type => .Select(type =>
{ {
if (cancellationToken.IsCancellationRequested)
return Tuple.Create(false, null as Exception);
bool anyRewritten = false; bool anyRewritten = false;
try try
{ {
@ -118,6 +123,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Framework
} }
catch (Exception e) catch (Exception e)
{ {
cancellationToken.Cancel();
return Tuple.Create(anyRewritten, e); return Tuple.Create(anyRewritten, e);
} }
}) })