Skip to content

Commit

Permalink
Improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgio committed Jul 29, 2024
1 parent cd732fe commit 6f7b6e9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
19 changes: 11 additions & 8 deletions core/src/main/kotlin/eu/iamgio/quarkdown/ast/quarkdown/Box.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 6f7b6e9

Please sign in to comment.