From 3ad6483bd0ddb4afb3e26c7184bcf1247847fee0 Mon Sep 17 00:00:00 2001 From: Axel Howind Date: Fri, 3 Nov 2023 10:48:02 +0100 Subject: [PATCH] provide more descriptive exception messages --- .../src/main/java/com/dua3/utility/logging/LogUtil.java | 2 +- .../main/java/com/dua3/utility/options/ArgumentsParser.java | 4 ++-- .../src/main/java/com/dua3/utility/text/RichTextBuilder.java | 2 +- utility/src/main/java/com/dua3/utility/text/TextUtil.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/utility-logging/src/main/java/com/dua3/utility/logging/LogUtil.java b/utility-logging/src/main/java/com/dua3/utility/logging/LogUtil.java index 0a8159a6..661c0f8d 100644 --- a/utility-logging/src/main/java/com/dua3/utility/logging/LogUtil.java +++ b/utility-logging/src/main/java/com/dua3/utility/logging/LogUtil.java @@ -16,7 +16,7 @@ private LogUtil() {} /** * Returns the global LogEntryDispatcher by using the available ILogEntryDispatcherFactory implementations loaded - * through ServiceLoaderand connects all known loggers to it. + * through ServiceLoader and connects all known loggers to it. * * @return The global LogEntryDispatcher instance. * @throws ServiceConfigurationError if no factories can create a LogEntryDispatcher. diff --git a/utility/src/main/java/com/dua3/utility/options/ArgumentsParser.java b/utility/src/main/java/com/dua3/utility/options/ArgumentsParser.java index 780d2a53..1fe2fe03 100644 --- a/utility/src/main/java/com/dua3/utility/options/ArgumentsParser.java +++ b/utility/src/main/java/com/dua3/utility/options/ArgumentsParser.java @@ -68,8 +68,8 @@ public ArgumentsParser(String name, String description, int minArgs, int maxArgs this.name = Objects.requireNonNull(name); this.description = Objects.requireNonNull(description); - LangUtil.check(minArgs >= 0); - LangUtil.check(maxArgs >= minArgs); + LangUtil.check(minArgs >= 0, "minimal number of arguments must not be negative: %s", minArgs); + LangUtil.check(maxArgs >= minArgs, "maximum number of arguments must be greater than or equal to the minimum number of arguments: %s (minimum number of arguments is %s", maxArgs, minArgs); this.minPositionalArgs = minArgs; this.maxPositionalArgs = maxArgs; } diff --git a/utility/src/main/java/com/dua3/utility/text/RichTextBuilder.java b/utility/src/main/java/com/dua3/utility/text/RichTextBuilder.java index b774ffd7..adab6236 100644 --- a/utility/src/main/java/com/dua3/utility/text/RichTextBuilder.java +++ b/utility/src/main/java/com/dua3/utility/text/RichTextBuilder.java @@ -259,7 +259,7 @@ public void push(String name, Object value) { */ public void pop(String name) { AttributeChange change = openedAttributes.pop(); - LangUtil.check(name.equals(change.name())); + LangUtil.check(name.equals(change.name()), "name does not match: \"%s\", expected \"%s\"", name, change.name()); Map attributes = split(); if (change.previousValue() == null) { attributes.remove(name); diff --git a/utility/src/main/java/com/dua3/utility/text/TextUtil.java b/utility/src/main/java/com/dua3/utility/text/TextUtil.java index c5bc0a93..9891aeb3 100644 --- a/utility/src/main/java/com/dua3/utility/text/TextUtil.java +++ b/utility/src/main/java/com/dua3/utility/text/TextUtil.java @@ -238,7 +238,7 @@ public static void transform(String template, // determine ref name int varEnd = template.indexOf(TRANSFORM_REF_END, pos); - LangUtil.check(varEnd != -1); + LangUtil.check(varEnd != -1, "unexpected end of template, '%s' expected", TRANSFORM_REF_END); String varName = template.substring(pos, varEnd); pos = varEnd + TRANSFORM_REF_END.length();