summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-09 09:23:27 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-09 09:23:27 -0400
commit19397a89ff6f0d216637e1272b78c7e15c85bf76 (patch)
tree93fa94b63f511f83ea77f201e930564878aa2a06 /src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs
parent311033964924b69961c3a9f3e21e6e3ea880910e (diff)
downloadSMAPI-19397a89ff6f0d216637e1272b78c7e15c85bf76.tar.gz
SMAPI-19397a89ff6f0d216637e1272b78c7e15c85bf76.tar.bz2
SMAPI-19397a89ff6f0d216637e1272b78c7e15c85bf76.zip
log detailed error for rewritten patch failures (#711)
Diffstat (limited to 'src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs')
-rw-r--r--src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs b/src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs
index 0f906f51..bca76981 100644
--- a/src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs
+++ b/src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs
@@ -1,3 +1,5 @@
+using System;
+using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
@@ -24,10 +26,30 @@ namespace StardewModdingAPI.Framework.RewriteFacades
return new Harmony(id);
}
+ /// <summary>Apply one or more patches to a method.</summary>
+ /// <param name="original">The original method.</param>
+ /// <param name="prefix">The prefix to apply.</param>
+ /// <param name="postfix">The postfix to apply.</param>
+ /// <param name="transpiler">The transpiler to apply.</param>
public DynamicMethod Patch(MethodBase original, HarmonyMethod prefix = null, HarmonyMethod postfix = null, HarmonyMethod transpiler = null)
{
- MethodInfo method = base.Patch(original: original, prefix: prefix, postfix: postfix, transpiler: transpiler);
- return new DynamicMethod(method.Name, method.Attributes, method.CallingConvention, method.ReturnType, method.GetParameters().Select(p => p.ParameterType).ToArray(), method.Module, true);
+ try
+ {
+ MethodInfo method = base.Patch(original: original, prefix: prefix, postfix: postfix, transpiler: transpiler);
+ return new DynamicMethod(method.Name, method.Attributes, method.CallingConvention, method.ReturnType, method.GetParameters().Select(p => p.ParameterType).ToArray(), method.Module, true);
+ }
+ catch (Exception ex)
+ {
+ var patchTypes = new List<string>();
+ if (prefix != null)
+ patchTypes.Add("prefix");
+ if (postfix != null)
+ patchTypes.Add("postfix");
+ if (transpiler != null)
+ patchTypes.Add("transpiler");
+
+ throw new Exception($"Failed applying {string.Join("/", patchTypes)} to method {original.DeclaringType?.FullName}.{original.Name}", ex);
+ }
}
}
}