Skip to content

Commit

Permalink
Merge pull request #480 from JetBrains/catch-message
Browse files Browse the repository at this point in the history
Improve messages in Logger.catch
  • Loading branch information
Iliya-usov authored Apr 19, 2024
2 parents 1a04cda + 5ac1c5f commit 429cb32
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions rd-kt/rd-core/src/main/kotlin/com/jetbrains/rd/util/Logger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,16 @@ inline fun Logger.error(msg: () -> Any?) = log(LogLevel.Error, msg)
fun Logger.error(msg: String?, throwable: Throwable) = log(LogLevel.Error, msg, throwable)
fun Logger.error(throwable: Throwable) = this.error(null, throwable)

object RdDefaultErrorLoggerHolder {
val defaultErrorLogger = getLogger("Default-Error-Logger")
}

inline fun Logger.catch(comment: String?, action:() -> Unit) {
try {
action()
} catch (e : Throwable) {
val sfx = if (comment.isNullOrBlank()) "" else ": $comment"
error("Catch$sfx", e)
val sfx = "${e.javaClass.name} ${e.message}" + if (comment.isNullOrBlank()) "" else " ($comment)"
error("Catch $sfx", e)
}
}
inline fun Logger.catch(action:() -> Unit) = catch (null, action)
Expand All @@ -128,11 +132,6 @@ inline fun catchAndDrop(action:() -> Unit) {
}

inline fun catch(comment: String?, action:() -> Unit) {
try {
action()
} catch (e : Throwable) {
val sfx = if (comment.isNullOrBlank()) "" else ": $comment"
getLogger("Default-Error-Logger").log(LogLevel.Error, "Catch$sfx", e)
}
RdDefaultErrorLoggerHolder.defaultErrorLogger.catch(comment, action)
}
inline fun catch(action:() -> Unit) = catch (null, action)

0 comments on commit 429cb32

Please sign in to comment.