From d748fe7696f7e6872b83e389469a458b32cd2ddb Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Thu, 27 Jul 2023 00:48:24 +0900 Subject: [PATCH] [Analysis API] Wrap compilation exceptions in KtCodeCompilationException --- .../api/components/KtCompilerFacility.kt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/analysis/analysis-api/src/org/jetbrains/kotlin/analysis/api/components/KtCompilerFacility.kt b/analysis/analysis-api/src/org/jetbrains/kotlin/analysis/api/components/KtCompilerFacility.kt index 6139e797888..515413bb5fa 100644 --- a/analysis/analysis-api/src/org/jetbrains/kotlin/analysis/api/components/KtCompilerFacility.kt +++ b/analysis/analysis-api/src/org/jetbrains/kotlin/analysis/api/components/KtCompilerFacility.kt @@ -96,9 +96,10 @@ public interface KtCompilerFacilityMixIn : KtAnalysisSessionMixIn { * * @return Compilation result. * - * The function _does not_ wrap unchecked exceptions from the compiler. - * The implementation should wrap the `compile()` call into a `try`/`catch` block if necessary. + * The function rethrows exceptions from the compiler, wrapped in [KtCodeCompilationException]. + * The implementation should wrap the `compile()` call into a `try`/`catch` block when necessary. */ + @Throws(KtCodeCompilationException::class) public fun compile( file: KtFile, configuration: CompilerConfiguration, @@ -106,7 +107,16 @@ public interface KtCompilerFacilityMixIn : KtAnalysisSessionMixIn { allowedErrorFilter: (KtDiagnostic) -> Boolean ): KtCompilationResult { return withValidityAssertion { - analysisSession.compilerFacility.compile(file, configuration, target, allowedErrorFilter) + try { + analysisSession.compilerFacility.compile(file, configuration, target, allowedErrorFilter) + } catch (e: Throwable) { + throw KtCodeCompilationException(e) + } } } -} \ No newline at end of file +} + +/** + * Thrown when an exception occurred on analyzing the code to be compiled, or during target platform code generation. + */ +public class KtCodeCompilationException(cause: Throwable) : RuntimeException(cause) \ No newline at end of file