TestHooker should print full stack trace of Exception thrown by custom classes

One day in my “VisualTestingInKatalonStudio” project when I run a test case, I got the following message :

2019-05-25 12:33:09.582 ERROR c.k.k.core.context.internal.TestHooker   - ❌ java.lang.IllegalArgumentException: reportsDir is expected to have dir name 'Reports' but not: /Users/urayamakazuaki/katalon-workspace/VisualTestingInKatalonStudio/Storage

com.kms.katalon.context.internal.TestHooker#invokeMethod() caught an IllegalArgumentException thrown by some of my custom classes.

I wanted to know which class, which method threw this IllegalArgumentException, and wanted to read the stack trace to seek for the root cause of the problem. But TestHooker did not show the most valuable stack trace. Without the stack trace, it was very hard to debug my problem. I got irritated.

I want TestHooker to print the full stack trace of Exceptions thrown by custom classes from inside test cases.

I have an idea how to change TestHooker, near line#135:

Now:

} catch (Throwable e) {
            logger.logError(ExceptionsUtil.getMessageForThrowable(e));
        

Modified

} catch (Throwable e) {
            logger.logError(ExceptionsUtil.getStackTraceForThrowable(e));
3 Likes

Sounds reasonable. We will add this into our backlog.

Cheers !

I managed to print the stack trace that I wanted to see. How did I do? Let me show you. It is a bit funny.

I identified the class and method by searching over *.groovy files with pattern “reportsDir is expected to have dir name”. Fortunately I could. Then how to get the stack trace? I made a tentative change to the class.

Original code of my class:

class MyClass {
    def myBuggyMethod() {
        def p
        ....
        if (someCondition on variable p) {
            ....
        } else {
           throw new IllegalArgumentException("reportsDir is expected to have dir name 'Reports' but not: " + p)
        }
    }
}

Tentative update:

class MyClass {
    def myBuggyMethod() {
        def p
        ....
        if (someCondition on variable p) {
            ....
        } else {
            try {
                throw new IllegalArgumentException("reportsDir is expected to have dir name 'Reports' but not: " + p)
            } catch (Exception e) {
                e.printStackTrace()   // print it before caught by TestHooker
                throw e
            }
        }
    }
}

This looks silly but works.

2 Likes