Skip to content

Commit 7845a70

Browse files
committed
Added offending name to exception to allow better debugging
1 parent e63b63c commit 7845a70

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/main/java/graphql/Assert.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static void assertTrue(boolean condition, String format, Object... args)
4040
throw new AssertException(format(format, args));
4141
}
4242

43-
private static final String invalidNameErrorMessage = "Name must be non-null, non-empty and match [_A-Za-z][_0-9A-Za-z]*";
43+
private static final String invalidNameErrorMessage = "Name must be non-null, non-empty and match [_A-Za-z][_0-9A-Za-z]* - was '%s'";
4444

4545
/**
4646
* Validates that the Lexical token name matches the current spec.
@@ -54,7 +54,7 @@ public static String assertValidName(String name) {
5454
if (name != null && !name.isEmpty() && name.matches("[_A-Za-z][_0-9A-Za-z]*")) {
5555
return name;
5656
}
57-
throw new AssertException(invalidNameErrorMessage);
57+
throw new AssertException(String.format(invalidNameErrorMessage,name));
5858
}
5959

6060
}

src/test/groovy/graphql/AssertTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class AssertTest extends Specification {
142142

143143
then:
144144
def error = thrown(AssertException)
145-
error.message == "Name must be non-null, non-empty and match [_A-Za-z][_0-9A-Za-z]*"
145+
error.message == "Name must be non-null, non-empty and match [_A-Za-z][_0-9A-Za-z]* - was '${name}'"
146146

147147
where:
148148
name | _

0 commit comments

Comments
 (0)