Wizard: make YamlParsingError to be exception error

This commit is contained in:
Ilya Kirillov
2020-03-07 19:15:51 +03:00
parent 00d8045adc
commit 98faaf9eba
2 changed files with 10 additions and 15 deletions
@@ -1,10 +1,6 @@
package org.jetbrains.kotlin.tools.projectWizard.wizard.core
import org.jetbrains.kotlin.tools.projectWizard.core.Error
import org.jetbrains.kotlin.tools.projectWizard.core.asString
import org.jetbrains.kotlin.tools.projectWizard.core.ExceptionError
import org.yaml.snakeyaml.parser.ParserException
data class YamlParsingError(val exception: ParserException) : Error() {
override val message: String
get() = exception.asString()
}
data class YamlParsingError(override val exception: ParserException) : ExceptionError()
@@ -9,7 +9,14 @@ abstract class Error {
abstract class ExceptionError : Error() {
abstract val exception: Exception
override val message: String
get() = exception.asString()
get() = exception::class.simpleName!!.removeSuffix("Exception").splitByWords() +
exception.message?.let { ": $it" }.orEmpty()
companion object {
private val wordRegex = "[A-Z][a-z0-9]+".toRegex()
private fun String.splitByWords() =
wordRegex.findAll(this).joinToString(separator = " ") { it.value }
}
}
data class IOError(override val exception: IOException) : ExceptionError()
@@ -79,11 +86,3 @@ data class ModuleNotFoundError(val path: String) : Error() {
}
fun Throwable.asString() =
this::class.simpleName!!.removeSuffix("Exception").splitByWords() + message?.let { ": $it" }.orEmpty()
private val wordRegex = "[A-Z][a-z0-9]+".toRegex()
private fun String.splitByWords() =
wordRegex.findAll(this).joinToString(separator = " ") { it.value }