-
Notifications
You must be signed in to change notification settings - Fork 287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KSPLogger.error does not fail compilation #122
Comments
I couldn't add a test for KSP because right now logging errors do not fail compilation in KSP. If by the time we need to run room compiler's failure tests, if it is still not implemented in KSP, I'll update the abstraction to track messages and throw error at the end of compilation. google/ksp#122. I've added a test to be enabled once that issue is fixed. Bug: 160322705 Test: XProcessingEnvTest Change-Id: Ied320bf329e026a71cc8c107f40e371e6bf8691e
To work around this, I wrap the logger in my own logger that throws a // TODO temporary until KSP's logger makes errors fail the build
private class FailOnErrorKSPLogger(private val delegate: KSPLogger) : KSPLogger by delegate {
private val hasErrors = AtomicBoolean(false)
override fun error(message: String, symbol: KSNode?) {
delegate.error(message, symbol)
hasErrors.set(true)
}
fun reportErrors() {
if (hasErrors.get()) {
throw CompilationErrorException()
}
}
}
// Later in my processor
override fun init(
options: Map<String, String>,
kotlinVersion: KotlinVersion,
codeGenerator: CodeGenerator,
logger: KSPLogger,
) {
this.logger = FailOnErrorKSPLogger(logger)
}
override fun finish() {
logger.reportErrors()
} |
I think you should not need this anymore. |
Still need a way to allow processors to fail and this seems a reasonable approach? |
Actually this start to work now.. Not sure how, potentially upstream fixed some logic around message collector. |
Calling KSPLogger should fail compilation after processing is done, otherwise, processors don't have a way to gracefully fail compilation.
The text was updated successfully, but these errors were encountered: