Skip to content
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

Merged
merged 1 commit into from
Jun 12, 2020
Merged

Conversation

kianzarrin
Copy link
Collaborator

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.

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 -- ");
Copy link
Collaborator Author

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

Copy link
Contributor

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().

Copy link
Member

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

Copy link
Member

@originalfoo originalfoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@originalfoo originalfoo added Harmony technical Tasks that need to be performed in order to improve quality and maintainability labels Jun 11, 2020
@originalfoo originalfoo added this to the 11.6.0 milestone Jun 11, 2020
@@ -94,6 +94,12 @@ public class TrafficManagerMod : IUserMod {
InGameHotReload = InGame();

HarmonyHelper.EnsureHarmonyInstalled();

#if DEBUG
const bool installHarmonyASAP = false; // set true for fast testing
Copy link
Contributor

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(); });
Copy link
Contributor

@DaEgi01 DaEgi01 Jun 11, 2020

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.

@kianzarrin kianzarrin merged commit 63eedc0 into master Jun 12, 2020
@kianzarrin kianzarrin deleted the harmony-debug branch June 12, 2020 02:31
kianzarrin added a commit that referenced this pull request Jun 12, 2020
krzychu124 added a commit that referenced this pull request Jun 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Harmony technical Tasks that need to be performed in order to improve quality and maintainability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants