diff --git a/1.7/Assemblies/BlaxCastes.dll b/1.7/Assemblies/BlaxCastes.dll
index 7d51865..da43a2c 100644
Binary files a/1.7/Assemblies/BlaxCastes.dll and b/1.7/Assemblies/BlaxCastes.dll differ
diff --git a/1.7/Assemblies/BlaxCastes.pdb b/1.7/Assemblies/BlaxCastes.pdb
index f0b51b5..53c219d 100644
Binary files a/1.7/Assemblies/BlaxCastes.pdb and b/1.7/Assemblies/BlaxCastes.pdb differ
diff --git a/About/About.xml b/About/About.xml
index b4ddc67..a96a4dc 100644
--- a/About/About.xml
+++ b/About/About.xml
@@ -3,7 +3,7 @@
Blax Castes
Blax Gaming
blax.castes
- 1.0.0
+ 1.0.1
1.7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9c165b0..747a881 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog
+## 1.0.1
+
+- Errors from other mods or the game in the hooked methods now keep their full stack trace, so they no longer look like Blax Castes errors.
+
## 1.0.0
- Castes: a caste bundles an apparel, food, drug and reading policy, a medical care level, a schedule, work priorities and, with [1001] Weapons Tab Reborn, a weapon loadout. Putting a pawn in a caste sets every slot the caste manages in one step. Prisoners get the food policy and medical care only; quest lodgers skip apparel, drugs, reading and the schedule; babies skip food.
diff --git a/Source/BlaxCastes/JoinHooks.cs b/Source/BlaxCastes/JoinHooks.cs
index 58746aa..d23e23c 100644
--- a/Source/BlaxCastes/JoinHooks.cs
+++ b/Source/BlaxCastes/JoinHooks.cs
@@ -312,10 +312,9 @@ namespace BlaxCastes
{
public static void Prefix(Pawn __instance, out LeaveState __state) => __state = JoinHooks.BeforeLeaving(__instance);
- public static Exception Finalizer(Exception __exception, LeaveState __state)
+ public static void Finalizer(LeaveState __state)
{
JoinHooks.AfterLeaving(__state);
- return __exception;
}
}
@@ -328,10 +327,9 @@ namespace BlaxCastes
{
public static void Prefix(Map map, out List __state) => __state = JoinHooks.BeforeMapClosed(map);
- public static Exception Finalizer(Exception __exception, List __state)
+ public static void Finalizer(List __state)
{
JoinHooks.AfterMapClosed(__state);
- return __exception;
}
}
@@ -348,10 +346,9 @@ namespace BlaxCastes
{
public static void Prefix(Map map, out List __state) => __state = JoinHooks.BeforePawnsLeave(map?.mapPawns?.AllPawnsSpawned);
- public static Exception Finalizer(Exception __exception, List __state)
+ public static void Finalizer(List __state)
{
JoinHooks.AfterMapClosed(__state);
- return __exception;
}
}
@@ -360,7 +357,8 @@ namespace BlaxCastes
/// and Trade as Slave or Colonist only set guest.joinStatus before this call, so the final status
/// (slave or not) picks the row. Selling: a "sold" scope keeps the slave-to-free step inside the sale
/// from queueing a join, and the finalizer writes the former-caste record with the status the pawn
- /// had before the sale. The finalizer pops the scope even when PreTraded throws.
+ /// had before the sale. The finalizer pops the scope even when PreTraded throws. It only reads
+ /// __exception and returns void, so Harmony rethrows the original exception with its stack trace.
///
[HarmonyPatch(typeof(Pawn), nameof(Pawn.PreTraded))]
internal static class Patch_Pawn_PreTraded
@@ -388,7 +386,7 @@ namespace BlaxCastes
}
}
- public static Exception Finalizer(Exception __exception, Pawn __instance, TradeState __state)
+ public static void Finalizer(Exception __exception, Pawn __instance, TradeState __state)
{
try
{
@@ -400,7 +398,6 @@ namespace BlaxCastes
{
JoinHooks.LogOnce("Trade scope", e);
}
- return __exception;
}
}
}
diff --git a/Tests/BlaxCastesTests/Source/SmokeTests.cs b/Tests/BlaxCastesTests/Source/SmokeTests.cs
index e5b550e..117ea75 100644
--- a/Tests/BlaxCastesTests/Source/SmokeTests.cs
+++ b/Tests/BlaxCastesTests/Source/SmokeTests.cs
@@ -39,6 +39,22 @@ namespace BlaxCastesTests
T.Check(warnings.Count == 0, "Blax Castes warnings at startup: " + string.Join(" | ", warnings.Take(3)));
}
+ [BlaxTest("startup: every Blax Castes finalizer returns void, so Harmony rethrows exceptions with their stack trace")]
+ public static void FinalizersReturnVoid()
+ {
+ // One finalizer returning Exception on a method makes Harmony "throw ex" instead of "rethrow"
+ // (0Harmony EmitFinalizers), which cuts the inner frames off every exception passing through it.
+ var finalizers = Harmony.GetAllPatchedMethods()
+ .Select(Harmony.GetPatchInfo)
+ .Where(info => info != null)
+ .SelectMany(info => info.Finalizers)
+ .Where(p => p.owner == BlaxCastesStartup.HarmonyId)
+ .ToList();
+ T.Check(finalizers.Count >= 4, "Blax Castes finalizers found: " + finalizers.Count + ", expected at least 4");
+ var bad = finalizers.Where(p => p.PatchMethod.ReturnType != typeof(void)).Select(p => p.PatchMethod.DeclaringType?.Name).ToList();
+ T.Check(bad.Count == 0, "finalizers that return a value: " + string.Join(", ", bad));
+ }
+
[BlaxTest("startup: settings, game component and strings are loaded")]
public static void Loaded()
{
diff --git a/Tests/BlaxCastesTests/Source/StatusTests.cs b/Tests/BlaxCastesTests/Source/StatusTests.cs
index af9e011..875fe19 100644
--- a/Tests/BlaxCastesTests/Source/StatusTests.cs
+++ b/Tests/BlaxCastesTests/Source/StatusTests.cs
@@ -736,7 +736,7 @@ namespace BlaxCastesTests
}
finally
{
- AccessTools.Method(patch, "Finalizer").Invoke(null, new object[] { null, prefixArgs[1] });
+ AccessTools.Method(patch, "Finalizer").Invoke(null, new object[] { prefixArgs[1] });
}
T.Equal(0, JoinScopes.Depth, "open join scopes after the map closed");
T.Check(!JoinDefaults.IsQueued(p), "the lost slave was queued (" + JoinDefaults.QueuedFor(p)?.reason + ")");
@@ -764,7 +764,7 @@ namespace BlaxCastesTests
}
finally
{
- AccessTools.Method(patch, "Finalizer").Invoke(null, new object[] { null, prefixArgs[1] });
+ AccessTools.Method(patch, "Finalizer").Invoke(null, new object[] { prefixArgs[1] });
}
T.Equal(0, JoinScopes.Depth, "open join scopes after " + method);
}