https://kotlinlang.org logo
#ksp
Title
# ksp
j

juliocbcotta

10/10/2023, 2:07 PM
Wouldn't it be possible to have better errors when KSP is applied to a project? For instance, the dev does some refactoring and some interface is missing or the package of a class changed... but all I can see is KSP errors. I understand that KSP won't be able to work properly, but KSP errors hide the problems we have in code... In this stack track I can't even see my projects code in the stacktrace and compiling the project again with "--stacktrace" does not help. Is there any way to allow me to see the java/kotlin errors in my code?
m

mbonnin

10/10/2023, 2:11 PM
This looks like an issue in the dagger processor. Processors can display better error messages
Although I wish processors had access to both line and column of
KsNode.location
for more precise reporting
But in your case, it looks like a matter of making the dagger processor more robust to source errors
Or maybe run more Kotlin analysis before running KSP? But then it's a chicken and egg problem I guess. Kotlin analysis needs the KSP symbols but KSP needs Kotlin analysis 🐔 🥚
j

juliocbcotta

10/10/2023, 2:28 PM
if we could know at least where in our code the processor found an issue, it would be great... so Should I open an issue in dagger repo?
I also see room stuff... room issue tracker?
m

mbonnin

10/10/2023, 2:40 PM
My guess would be dagger because it comes first in the package name but not sure
Someone filed it already actually: https://github.com/google/dagger/issues/4042
e

elihart

10/12/2023, 7:53 PM
I ran into this a few days ago too. One of our internal processors threw an exception because it encountered an “Error” type when it expected a real implementation. The problem was that the import statement was missing. unfortunately, since ksp runs before the kotlin compile task the import issue wasn’t shown at all in error logs and it was quite hard to figure out the root cause. I updated our processor to check for the Error type case and not throw, but it is a bit difficult to always do that, and it seems like there should be a better way to ensure compilation errors with the compiler are always reported
m

mbonnin

10/12/2023, 8:26 PM
Definitely not an expert but I'd expect this to be a really hard problem. KSP generates symbols that can be used from your main source set. Running the Kotlin compiler before KSP isn't really an option for that reason.
2
A place where it could be implemented is for special processors that generate code that's only used by reflection like moshi for an example
But the general case sounds quite hard.