[FIR] extract exception handing into a service to have additional implementation for the ide

This commit is contained in:
Ilya Kirillov
2022-12-28 14:44:43 +01:00
committed by Space Team
parent 90436abb23
commit 79fe4100aa
5 changed files with 62 additions and 33 deletions
@@ -17,16 +17,8 @@ class SourceCodeAnalysisException(val source: KtSourceElement, override val caus
override val message get() = cause.classNameAndMessage
}
inline fun <R> whileAnalysing(element: KtSourceElement?, block: () -> R): R {
return try {
block()
} catch (throwable: Throwable) {
throw throwable.wrapIntoSourceCodeAnalysisExceptionIfNeeded(element)
}
}
@PublishedApi
internal fun Throwable.wrapIntoSourceCodeAnalysisExceptionIfNeeded(element: KtSourceElement?) = when (this) {
fun Throwable.wrapIntoSourceCodeAnalysisExceptionIfNeeded(element: KtSourceElement?) = when (this) {
is SourceCodeAnalysisException -> this
is IndexNotReadyException -> this
is ControlFlowException -> this
@@ -49,21 +41,7 @@ class FileAnalysisException(
}
}
inline fun <R> withFileAnalysisExceptionWrapping(
filePath: String?,
fileSource: AbstractKtSourceElement?,
crossinline linesMapping: (Int) -> Pair<Int, Int>?,
block: () -> R,
): R {
return try {
block()
} catch (throwable: Throwable) {
throw throwable.wrapIntoFileAnalysisExceptionIfNeeded(filePath, fileSource) { linesMapping(it) }
}
}
@PublishedApi
internal fun Throwable.wrapIntoFileAnalysisExceptionIfNeeded(
fun Throwable.wrapIntoFileAnalysisExceptionIfNeeded(
filePath: String?,
fileSource: AbstractKtSourceElement?,
linesMapping: (Int) -> Pair<Int, Int>?,