From 6f7b6e918855a25179de800cb9a389a98bebc76d Mon Sep 17 00:00:00 2001 From: Giorgio Garofalo Date: Tue, 30 Jul 2024 00:15:04 +0200 Subject: [PATCH] Improve error messages --- .../eu/iamgio/quarkdown/ast/quarkdown/Box.kt | 19 +++++++++++-------- .../function/call/FunctionCallNodeExpander.kt | 2 +- .../error/FunctionRuntimeException.kt | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/core/src/main/kotlin/eu/iamgio/quarkdown/ast/quarkdown/Box.kt b/core/src/main/kotlin/eu/iamgio/quarkdown/ast/quarkdown/Box.kt index 9d34651b..b5b85d6e 100644 --- a/core/src/main/kotlin/eu/iamgio/quarkdown/ast/quarkdown/Box.kt +++ b/core/src/main/kotlin/eu/iamgio/quarkdown/ast/quarkdown/Box.kt @@ -30,15 +30,18 @@ data class Box( /** * A custom box that shows an error message. * @param message error message to display + * @param title additional error title * @return a custom box containing the error message */ - fun error(message: String) = - Box( - title = listOf(Text("Error")), - padding = null, - backgroundColor = Color(224, 67, 64), - foregroundColor = Color(255, 255, 255), - children = listOf(CodeSpan(message)), - ) + fun error( + message: String, + title: String? = null, + ) = Box( + title = listOf(Text("Error" + if (title != null) ": $title" else "")), + padding = null, + backgroundColor = Color(224, 67, 64), + foregroundColor = Color(255, 255, 255), + children = listOf(CodeSpan(message)), + ) } } diff --git a/core/src/main/kotlin/eu/iamgio/quarkdown/function/call/FunctionCallNodeExpander.kt b/core/src/main/kotlin/eu/iamgio/quarkdown/function/call/FunctionCallNodeExpander.kt index 9d25b4bc..aa71f209 100644 --- a/core/src/main/kotlin/eu/iamgio/quarkdown/function/call/FunctionCallNodeExpander.kt +++ b/core/src/main/kotlin/eu/iamgio/quarkdown/function/call/FunctionCallNodeExpander.kt @@ -50,7 +50,7 @@ class FunctionCallNodeExpander( } catch (e: PipelineException) { // If the function call is invalid. errorHandler.handle(e) { message -> - appendOutput(node, Box.error(message)) // Shows an error message box in the final document. + appendOutput(node, Box.error(message, title = call.name)) // Shows an error message box in the final document. } } } diff --git a/core/src/main/kotlin/eu/iamgio/quarkdown/function/error/FunctionRuntimeException.kt b/core/src/main/kotlin/eu/iamgio/quarkdown/function/error/FunctionRuntimeException.kt index b7d00555..173a98bb 100644 --- a/core/src/main/kotlin/eu/iamgio/quarkdown/function/error/FunctionRuntimeException.kt +++ b/core/src/main/kotlin/eu/iamgio/quarkdown/function/error/FunctionRuntimeException.kt @@ -7,7 +7,7 @@ import eu.iamgio.quarkdown.pipeline.error.PipelineException * An exception thrown when an error occurs inside a called function. * @param message error message */ -class FunctionRuntimeException(message: String) : PipelineException("A runtime error occurred: $message", RUNTIME_ERROR_EXIT_CODE) { +class FunctionRuntimeException(message: String) : PipelineException(message, RUNTIME_ERROR_EXIT_CODE) { /** * @param throwable the error cause */