Skip to content

Commit

Permalink
Fix string formatting issues with annotations
Browse files Browse the repository at this point in the history
There were issues when the error message contained the string "{}"
  • Loading branch information
misode committed Sep 27, 2024
1 parent 3c59ee8 commit ca4739e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/main/java/io/github/misode/packtest/LoadDiagnostics.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
public class LoadDiagnostics {
private static final List<Diagnostic> 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<Diagnostic> loadErrors() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit ca4739e

Please sign in to comment.