StrongJoshua / libgdx-inGameConsole

A LibGdx library that allows a developer to add a console (similar to how it is featured in Source games) to their game.
https://www.strongjoshua.net/projects/games/libgdx-ingame-console
Apache License 2.0
132 stars 34 forks source link

Commands now give useful error messages even without consoleTrace active #50

Open klianc09 opened 4 years ago

klianc09 commented 4 years ago

When consoleTrace is set to false, exceptions in commands will lead to useless messages:

Exception occurred in method: failFunction

This is caused by the fact that com.badlogic.gdx.utils.reflect.invoke() wraps the TargetInvokationException with a ReflectionException with that predefined message, therefore the check for an empty message in AbstractConsole is never true in that case.

if (msg == null || msg.length() <= 0) {
  msg = "Unknown Error";
  e.printStackTrace();
}

With this change the example failFunction command in Box2DTest will print the much more helpful:

Exception occurred in method: failFunction
java.lang.RuntimeException: This function was designed to fail.

Only tested on desktop. If it causes issues with GWT, the import might need to be avoided, but so far untested.