All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.jetbrains.datalore.plot.config.FailureHandler.kt Maven / Gradle / Ivy

/*
 * Copyright (c) 2019. JetBrains s.r.o.
 * Use of this source code is governed by the MIT license that can be found in the LICENSE file.
 */

package jetbrains.datalore.plot.config

import jetbrains.datalore.base.gcommon.base.Throwables

object FailureHandler {
    fun failureInfo(e: RuntimeException): FailureInfo {
        @Suppress("NAME_SHADOWING")
        val e = Throwables.getRootCause(e)
        return if (!e.message.isNullOrBlank() && (
//                    e is IllegalStateException ||
                    e is IllegalArgumentException)
        ) {
            // Not a bug - likely user configuration error like `No layers in plot`
            FailureInfo(e.message!!, false)
        } else {
            val className = e::class.simpleName ?: ""
            FailureInfo(
                "Internal error: $className : ${e.message ?: ""}",
                true
            )
        }
    }

    class FailureInfo(val message: String, val isInternalError: Boolean)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy