Skip to content

Commit

Permalink
Handle exceptions in newly added API methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ileasile committed Oct 13, 2021
1 parent c17c094 commit 7e98b03
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ enum class LibraryProblemPart(val message: String) {
INIT("init codes"),
RESOURCES("resources definitions"),
RENDERERS("renderers"),
THROWABLE_RENDERERS("throwable renderers"),
CONVERTERS("converters (fields callbacks)"),
CLASS_ANNOTATIONS("class annotations callbacks"),
FILE_ANNOTATIONS("file annotations callbacks"),
BEFORE_CELL_CALLBACKS("initCell codes (before-cell-execution callbacks)"),
AFTER_CELL_CALLBACKS("after-cell-execution callbacks"),
INTERNAL_VARIABLES_MARKERS("internal variables markers"),
SHUTDOWN("shutdown callbacks/codes"),
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
package org.jetbrains.kotlinx.jupyter.codegen

import org.jetbrains.kotlinx.jupyter.api.ThrowableRenderer
import org.jetbrains.kotlinx.jupyter.exceptions.LibraryProblemPart
import org.jetbrains.kotlinx.jupyter.exceptions.ReplLibraryException
import org.jetbrains.kotlinx.jupyter.exceptions.rethrowAsLibraryException

class ThrowableRenderersProcessorImpl : ThrowableRenderersProcessor {
private val renderers = mutableListOf<ThrowableRenderer>()

override fun renderThrowable(throwable: Throwable): Any? {
return renderers.firstOrNull { it.accepts(throwable) }?.render(throwable)
return try {
rethrowAsLibraryException(LibraryProblemPart.THROWABLE_RENDERERS) {
renderers.firstOrNull { it.accepts(throwable) }?.render(throwable)
}
} catch (ex: ReplLibraryException) {
"""
Exception thrown while rendering another exception. Original exception:
${throwable.stackTraceToString()}
Rendering exception:
${ex.stackTraceToString()}
""".trimIndent()
}
}

override fun register(renderer: ThrowableRenderer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.jetbrains.kotlinx.jupyter.repl.impl

import org.jetbrains.kotlinx.jupyter.api.InternalVariablesMarker
import org.jetbrains.kotlinx.jupyter.exceptions.LibraryProblemPart
import org.jetbrains.kotlinx.jupyter.exceptions.rethrowAsLibraryException
import org.jetbrains.kotlinx.jupyter.repl.InternalVariablesMarkersProcessor
import kotlin.reflect.KProperty

Expand All @@ -12,6 +14,8 @@ class InternalVariablesMarkersProcessorImpl : InternalVariablesMarkersProcessor
}

override fun isInternal(property: KProperty<*>): Boolean {
return markers.any { it.isInternal(property) }
return rethrowAsLibraryException(LibraryProblemPart.INTERNAL_VARIABLES_MARKERS) {
markers.any { it.isInternal(property) }
}
}
}

0 comments on commit 7e98b03

Please sign in to comment.