https://kotlinlang.org logo
Title
j

Jiaxiang

02/11/2021, 11:06 PM
@Zac Sweers can you give me a reproduce repo for your
CompilationErrorException
use case?
z

Zac Sweers

02/11/2021, 11:09 PM
here's my WIP PR: https://github.com/ZacSweers/MoshiX/pull/84 Repro via
./gradlew :moshi-ksp:moshi-ksp:test
, which relies on this behavior in
JsonClassSymbolProcessorTest
. The code for the logger that throws this is in
JsonClassSymbolProcessor
itself, near the bottom. It just wraps
KSPLogger
and throws it in
finish()
if any errors were recorded
👍 1
a

Alex Vanyo

02/12/2021, 2:59 AM
I have a pretty similar setup, with a commit updating to
1.4.30-1.0.0-alpha02
here: https://github.com/livefront/sealed-enum/pull/32/commits/a02cd4050c17b1e8d146b465db0bc4c9716b3133 It looks like the behavior is now:
SymbolProcessor.finish()
is now only called if the compilation was successful (logger had previously encountered no errors)
SymbolProcessor.onError()
is called instead if the compilation wasn't successful, and throwing
CompilationErrorException()
here still fails compilation. However, since the logging is now deferred until after
finish()
and
onError()
, when I threw the error in
CompilationErrorException()
my errors are never actually logged. Right now I cast the
logger
to
MessageCollectorBasedKSPLogger
as a workaround to print the errors before throwing to still get a
KotlinCompilation.ExitCode.COMPILATION_ERROR
, but that probably shouldn't be necessary.
z

Zac Sweers

02/14/2021, 6:11 AM
nice find
t

Ting-Yuan Huang

02/24/2021, 1:59 AM
This issues is hidden in normal Gradle use cases and only reproducible with kotlin compile testing. Jiaxiang is working on a proper fix so that you won't need to throw the
CompilationErrorException
as a workaround.
👍 2