google / google/ksp

KSP hides Kotlin errors

Open
#2,668 0 comments 4 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
3.5k
Forks
415
Avg merge
1d 2h
Merged PRs (30d)
53

Description

For example:
```
> Task :web:status-history:kspKotlin FAILED
e: [ksp] java.lang.IllegalStateException: Unexpected type ERROR CLASS: Symbol not found for Instant

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':web:status-history:kspKotlin'.
> A failure occurred while executing com.google.devtools.ksp.gradle.KspAAWorkerAction
> Unexpected type ERROR CLASS: Symbol not found for Instant
```

All I know is which module that has the problem. How do I find out which file/line/etc. is the problem?!

When I do `gradlew build --stacktrace` I get some additional info:
```
Caused by: java.lang.IllegalStateException: Unexpected type ERROR CLASS: Symbol not found for Instant
at com.google.devtools.ksp.impl.symbol.kotlin.UtilKt.replace(util.kt:661)
at com.google.devtools.ksp.impl.symbol.kotlin.KSTypeImpl.starProjection(KSTypeImpl.kt:135)
at io.micronaut.kotlin.processing.visitor.KotlinClassElement$plainKotlinType$2.invoke(KotlinClassElement.kt:99)
at io.micronaut.kotlin.processing.visitor.KotlinClassElement$plainKotlinType$2.invoke(KotlinClassElement.kt:98)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:86)
at io.micronaut.kotlin.processing.visitor.KotlinClassElement.getPlainKotlinType(KotlinClassElement.kt:98)
at io.micronaut.kotlin.processing.visitor.KotlinClassElement.isAssignable(KotlinClassElement.kt:591)
at io.micronaut.kotlin.processing.visitor.KotlinClassElement.getAccessibleStaticCreators$lambda$3$lambda$2(KotlinClassElement.kt:363)
at io.micronaut.inject.ast.utils.EnclosedElementsQuery.lambda$getEnclosedElements$0(EnclosedElementsQuery.java:109)
at io.micronaut.inject.ast.utils.EnclosedElementsQuery.getElements(EnclosedElementsQuery.java:376)
at io.micronaut.inject.ast.utils.EnclosedElementsQuery.getEnclosedElements(EnclosedElementsQuery.java:180)
at io.micronaut.kotlin.processing.visitor.KotlinClassElement.getEnclosedElements(KotlinClassElement.kt:698)
at io.micronaut.kotlin.processing.visitor.KotlinClassElement.getAccessibleStaticCreators(KotlinClassElement.kt:354)
at io.micronaut.inject.ast.ClassElement.findStaticCreator(ClassElement.java:306)
at io.micronaut.inject.ast.ClassElement.getPrimaryConstructor(ClassElement.java:241)
at io.micronaut.kotlin.processing.visitor.KotlinClassElement.access$getPrimaryConstructor$s1957468439(KotlinClassElement.kt:72)
at io.micronaut.kotlin.processing.visitor.KotlinClassElement$resolvedPrimaryConstructor$2.invoke(KotlinClassElement.kt:208)
at io.micronaut.kotlin.processing.visitor.KotlinClassElement$resolvedPrimaryConstructor$2.invoke(KotlinClassElement.kt:207)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:86)
at io.micronaut.kotlin.processing.visitor.KotlinClassElement.getResolvedPrimaryConstructor(KotlinClassElement.kt:207)
at io.micronaut.kotlin.processing.visitor.KotlinClassElement.getPrimaryConstructor(KotlinClassElement.kt:660)
at io.micronaut.inject.processing.BeanDefinitionCreatorFactory.isDeclaredBean(BeanDefinitionCreatorFactory.java:94)
at io.micronaut.inject.processing.BeanDefinitionCreatorFactory.produce(BeanDefinitionCreatorFactory.java:73)
at io.micronaut.kotlin.processing.beans.BeanDefinitionProcessor.processClassDeclarations(BeanDefinitionProcessor.kt:93)
at io.micronaut.kotlin.processing.beans.BeanDefinitionProcessor.process(BeanDefinitionProcessor.kt:59)
at com.google.devtools.ksp.impl.KotlinSymbolProcessing$execute$1$1.invoke(KotlinSymbolProcessing.kt:566)
at com.google.devtools.ksp.impl.KotlinSymbolProcessing$execute$1$1.invoke(KotlinSymbolProcessing.kt:564)
at ksp.com.google.devtools.ksp.common.IncrementalContextBase.closeFilesOnException(IncrementalContextBase.kt:400)
at com.google.devtools.ksp.impl.KotlinSymbolProcessing.execute(KotlinSymbolProcessing.kt:564)
at com.google.devtools.ksp.impl.KSPLoader$Companion.loadAndRunKSP(KSPLoader.kt:37)
at com.google.devtools.ksp.impl.KSPLoader.loadAndRunKSP(KSPLoader.kt)
```
but overall still pretty useless compared to what we get without using KSP altogether:
```
> Task :web:status-history:compileKotlin FAILED
e: web/status-history/src/main/java/net/twisterrob/travel/statushistory/controller/InternalFeedbackController.kt:10:25 [UNRESOLVED_IMPORT] Unresolved reference 'Clock'.
e: web/status-history/src/main/java/net/twisterrob/travel/statushistory/controller/InternalFeedbackController.kt:29:36 [UNRESOLVED_REFERENCE] Unresolved reference 'Clock'.
e: web/status-history/src/main/java/net/twisterrob/travel/statushistory/infrastructure/DatastoreStatusHistoryDataSource.kt:15:25 [UNRESOLVED_IMPORT] Unresolved reference 'Instant'.
e: web/status-history/src/main/java/net/twisterrob/travel/statushistory/infrastructure/DatastoreStatusHistoryDataSource.kt:82:15 [UNRESOLVED_REFERENCE] Unresolved reference 'Instant'.
e: web/status-history/src/main/java/net/twisterrob/travel/statushistory/infrastructure/DatastoreStatusHistoryDataSource.kt:83:36 [UNRESOLVED_REFERENCE] Unresolved reference 'epochSeconds'.
e: web/status-history/src/main/java/net/twisterrob/travel/statushistory/infrastructure/DatastoreStatusHistoryDataSource.kt:83:50 [UNRESOLVED_REFERENCE] Unresolved reference 'nanosecondsOfSecond'.
e: web/status-history/src/main/java/net/twisterrob/travel/statushistory/infrastructure/DatastoreStatusHistoryDataSource.kt:124:38 [UNRESOLVED_REFERENCE] Unresolved reference 'Instant'.
e: web/status-history/src/main/java/net/twisterrob/travel/statushistory/infrastructure/DatastoreStatusHistoryDataSource.kt:125:4 [UNRESOLVED_REFERENCE] Unresolved reference 'Instant'.
e: web/status-history/src/main/java/net/twisterrob/travel/statushistory/infrastructure/HttpStatusDataSource.kt:4:25 [UNRESOLVED_IMPORT] Unresolved reference 'Clock'.
e: web/status-history/src/main/java/net/twisterrob/travel/statushistory/infrastructure/HttpStatusDataSource.kt:25:13 [UNRESOLVED_REFERENCE] Unresolved reference 'Clock'.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':web:status-history:compileKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
> Compilation error. See log for more details
```

The developer experience KSP provides for errors can't be: "Remove KSP to get error reporting.", please improve this in some way 🙏🏻.

(In the above example I was lucky it was trivial to remove KSP [commented out the plugin], in other projects I had to guess every time there was a compilation error.)

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with the :web:status-history:kspKotlin task and compare its output with compileKotlin, especially the reported files under web/status-history/src/main/java. Start from the KSP diagnostic path shown in the stack trace; done means KSP reports the unresolved source file and line instead of only the module-level ERROR CLASS.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
developer-experience
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.