From c3e979270956b8df9380cf9eea067048f325dbd3 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Fri, 14 Aug 2020 13:25:48 +0200 Subject: Replace !! with some meaningful messages --- plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt | 7 ++++++- .../base/src/main/kotlin/renderers/html/HtmlRenderer.kt | 14 ++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'plugins/base') diff --git a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt index d9ff924b..41dffa07 100644 --- a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt @@ -4,6 +4,8 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking +import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet +import org.jetbrains.dokka.DokkaException import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.resolvers.local.LocationProvider import org.jetbrains.dokka.model.DisplaySourceSet @@ -157,7 +159,10 @@ abstract class DefaultRenderer( } open suspend fun renderPage(page: PageNode) { - val path by lazy { locationProvider.resolve(page, skipExtension = true)!! } + val path by lazy { + locationProvider.resolve(page, skipExtension = true) + ?: throw DokkaException("Cannot resolve path for ${page.name}") + } when (page) { is ContentPage -> outputWriter.write(path, buildPage(page) { c, p -> buildPageContent(c, p) }, ".html") is RendererSpecificPage -> when (val strategy = page.strategy) { diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index d9833e43..0d20e8ac 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -523,11 +523,16 @@ open class HtmlRenderer( } private fun FlowContent.buildLink(to: PageNode, from: PageNode) = - buildLink(locationProvider.resolve(to, from)!!) { + locationProvider.resolve(to, from)?.let { path -> + buildLink(path) { + text(to.name) + } + } ?: span { + attributes["data-unresolved-link"] = to.name.htmlEscape() text(to.name) } - private fun FlowContent.buildAnchor(pointingTo: String) { + fun FlowContent.buildAnchor(pointingTo: String) { span(classes = "anchor-wrapper") { span(classes = "anchor-icon") { attributes["pointing-to"] = pointingTo @@ -551,7 +556,8 @@ open class HtmlRenderer( platforms: List, from: PageNode? = null, block: FlowContent.() -> Unit - ) = buildLink(locationProvider.resolve(to, platforms.toSet(), from)!!, block) + ) = locationProvider.resolve(to, platforms.toSet(), from)?.let { buildLink(it, block) } + ?: run { context.logger.error("Cannot resolve path for $to"); block() } override fun buildError(node: ContentNode) { context.logger.error("Unknown ContentNode type: $node") @@ -603,7 +609,7 @@ open class HtmlRenderer( override suspend fun renderPage(page: PageNode) { super.renderPage(page) if (page is ContentPage && page !is ModulePageNode && page !is PackagePageNode) - searchbarDataInstaller.processPage(page, locationProvider.resolve(page)) + searchbarDataInstaller.processPage(page, locationProvider.resolve(page) ?: context.logger.error("Cannot resolve path for ${page.dri}")) } override fun FlowContent.buildText(textNode: ContentText) = -- cgit