[Analysis API] do not create multiple attachments inside exceptions

This commit is contained in:
Ilya Kirillov
2022-08-03 10:46:16 +02:00
parent ddbd89aea7
commit f45f1ba3dc
30 changed files with 319 additions and 278 deletions
@@ -41,23 +41,6 @@ open class KotlinExceptionWithAttachments : RuntimeException, ExceptionWithAttac
}
fun KotlinExceptionWithAttachments.withAttachmentBuilder(
name: String,
buildContent: StringBuilder.() -> Unit
): KotlinExceptionWithAttachments {
return withAttachment(name, buildString { buildContent() })
}
fun <T> KotlinExceptionWithAttachments.withAttachmentDetailed(
name: String,
content: T?,
render: (T) -> String
): KotlinExceptionWithAttachments {
withAttachment("${name}Class", content?.let { it::class.java.name })
withAttachment(name, content?.let(render))
return this
}
@OptIn(ExperimentalContracts::class)
inline fun checkWithAttachment(value: Boolean, lazyMessage: () -> String, attachments: (KotlinExceptionWithAttachments) -> Unit = {}) {
contract { returns() implies (value) }
@@ -68,14 +51,3 @@ inline fun checkWithAttachment(value: Boolean, lazyMessage: () -> String, attach
throw e
}
}
inline fun errorWithAttachment(
message: String,
cause: Throwable? = null,
attachments: KotlinExceptionWithAttachments.() -> Unit = {}
): Nothing {
val exception = KotlinExceptionWithAttachments(message, cause)
attachments(exception)
throw exception
}