-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it easier to debug harmony problems #933
Conversation
Log.Info(e.StackTrace); | ||
Log.Error("Could not apply Harmony patches because the following exception occured:\n " + | ||
e + | ||
"\n -- End of inner exception stack trace -- "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stack trace from error would be appended to the end of the log
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, exception.ToString() is much better than the alternatives, since we have all the infos right there. No need to do basically the same with e.Message.ToString() + e.StackTrace.ToString().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One problem: have you tried causing an error?
Re-thrown exception from CitiesHarmony doesn't put any useful information where was the problem. It's general info: "...an error occurred while patching, blah, blah, blah..."
I noticed it when I've been experimenting with migration of TrainAI redirection to harmony and I renamed parameter names. Back then I've had to run debugger to get any info what was wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
@@ -94,6 +94,12 @@ public class TrafficManagerMod : IUserMod { | |||
InGameHotReload = InGame(); | |||
|
|||
HarmonyHelper.EnsureHarmonyInstalled(); | |||
|
|||
#if DEBUG | |||
const bool installHarmonyASAP = false; // set true for fast testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the solution but I guess its better than nothing for the time beeing.
So i m fine with that.
#if DEBUG | ||
const bool installHarmonyASAP = false; // set true for fast testing | ||
if (installHarmonyASAP) | ||
HarmonyHelper.DoOnHarmonyReady(delegate () { Patcher.Create().Install(); }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use lambdas instead?
this delegate () syntax is out of vogue since c# 3.0 and only left in for backwards compat.
This reverts commit 2374027.
Problem: If an exception occurs in a harmony patch in TargetMethod, The exception is not printed. Also, I have to wait until the game is loaded to test if my harmony patch has an exception or not.
Solution: I added a conditional code to test harmony patches when mod is enabled. Also, I changed the code to print all layers of the exception log.