From ca4739e36b23ac96baba12cd926e0fb6270d9d6c Mon Sep 17 00:00:00 2001 From: Misode Date: Fri, 27 Sep 2024 22:31:03 +0200 Subject: [PATCH] Fix string formatting issues with annotations There were issues when the error message contained the string "{}" --- .../io/github/misode/packtest/LoadDiagnostics.java | 10 +++++----- .../misode/packtest/mixin/LogTestReporterMixin.java | 10 ++++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/io/github/misode/packtest/LoadDiagnostics.java b/src/main/java/io/github/misode/packtest/LoadDiagnostics.java index ee42226..1e27fda 100644 --- a/src/main/java/io/github/misode/packtest/LoadDiagnostics.java +++ b/src/main/java/io/github/misode/packtest/LoadDiagnostics.java @@ -8,13 +8,13 @@ public class LoadDiagnostics { private static final List DIAGNOSTICS = new ArrayList<>(); - public static void error(Logger logger, String resource, String id, String message) { - DIAGNOSTICS.add(new Diagnostic(resource, id, message)); - String annotation = ""; + public static void error(Logger logger, String type, String id, String message) { + DIAGNOSTICS.add(new Diagnostic(type, id, message)); if (PackTest.isAnnotationsEnabled()) { - annotation = "\n::error title=Failed to load " + resource + " " + id + "::" + message; + logger.info(PackTest.wrapError("Failed to load {} {}") + "\n::error title=Failed to load {} {}::{}", type, id, type, id, message); + } else { + logger.info(PackTest.wrapError("Failed to load {} {} - {}"), type, id, message); } - logger.info(PackTest.wrapError("Failed to load {} {}" + (PackTest.isAnnotationsEnabled() ? "" : " - {}")) + annotation, resource, id, message); } public static List loadErrors() { diff --git a/src/main/java/io/github/misode/packtest/mixin/LogTestReporterMixin.java b/src/main/java/io/github/misode/packtest/mixin/LogTestReporterMixin.java index f1edbde..9b12755 100644 --- a/src/main/java/io/github/misode/packtest/mixin/LogTestReporterMixin.java +++ b/src/main/java/io/github/misode/packtest/mixin/LogTestReporterMixin.java @@ -29,17 +29,19 @@ public class LogTestReporterMixin { @Inject(method = "onTestFailed", at = @At(value = "HEAD"), cancellable = true) private void onTestFailed(GameTestInfo info, CallbackInfo ci) { if (PackTest.isAutoEnabled()) { + String testName = info.getTestName(); String lineNumber = info.getError() instanceof LineNumberException err ? " on line " + err.getLineNumber() : ""; + String message = Util.describeError(info.getError()); if (info.isRequired()) { - String annotation = ""; if (PackTest.isAnnotationsEnabled()) { - annotation = "\n::error title=Test " + info.getTestName() + " failed" + lineNumber + "!::" + Util.describeError(info.getError()); + LOGGER.error(PackTest.wrapError("{} failed{}!") + "\n::error title=Test {} failed{}!::{}", testName, lineNumber, testName, lineNumber, message); + } else { + LOGGER.error(PackTest.wrapError("{} failed{}! {}"), testName, lineNumber, message); } - LOGGER.error(PackTest.wrapError("{} failed{}!" + (PackTest.isAnnotationsEnabled() ? "" : " {}")) + annotation, info.getTestName(), lineNumber, Util.describeError(info.getError())); } else { - LOGGER.warn(PackTest.wrapWarning("(optional) {} failed{}! {}"), info.getTestName(), lineNumber, Util.describeError(info.getError())); + LOGGER.warn(PackTest.wrapWarning("(optional) {} failed{}! {}"), testName, lineNumber, message); } ci.cancel(); }