Skip to content

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

Open
klianc09 wants to merge 1 commit into
StrongJoshua:masterfrom
klianc09:master
Open

Commands now give useful error messages even without consoleTrace active#50
klianc09 wants to merge 1 commit into
StrongJoshua:masterfrom
klianc09:master

Conversation

@klianc09

Copy link
Copy Markdown

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.

log(e, LogLevel.ERROR);
} else if (e.getCause() instanceof InvocationTargetException) {
Throwable originalException = e.getCause().getCause();
if (originalException != null) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What if originalException is null? What should be the appropriate action? Simply ignore?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants