tschuchortdev / kotlin-compile-testing

A library for testing Kotlin and Java annotation processors, compiler plugins and code generation
Mozilla Public License 2.0
648 stars 61 forks source link

Checking Exceptions throwing by KSP processor #325

Open vdshb opened 1 year ago

vdshb commented 1 year ago

I want to check exception that my KSP processor throwing. But compilation.compile() is not re-throwing it, but logging instead:

e: Error occurred in KSP, check log for detail
e: [ksp] <... stack trace ...>

Is there an option to make com.tschuchort.compiletesting.KotlinCompilation#compile re-throw exceptions from KSP processor?

It's worth adding such option if it's not exist.

tschuchortdev commented 1 year ago

I'll look at this later and see if there's any way to forward the exceptions but unfortunately I'm 90% sure that it won't be possible with the current implementation because KCT is essentially calling Kotlin compiler classes one level below the kotlinc CLI. At that point the Kotlin compiler will have already caught the exception and converted it to the CLI error message that you see in the logs. In any case I'll leave this ticket open as a reminder for a future rewrite that will call the compiler more directly and hopefully enable more introspection.