Skip to content

Commit

Permalink
Error on typos for uniqueness
Browse files Browse the repository at this point in the history
  • Loading branch information
gem-neo4j committed Dec 5, 2024
1 parent f6a13c9 commit 9158435
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/src/main/java/apoc/path/PathExplorer.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,13 @@ private Uniqueness getUniqueness(String uniqueness) {
for (Uniqueness u : Uniqueness.values()) {
if (u.name().equalsIgnoreCase(uniqueness)) return u;
}
return UNIQUENESS;
throw new RuntimeException("Invalid uniqueness: '" + uniqueness + "'. Must be one of: "
+ String.join(
", ",
java.util.Arrays.stream(Uniqueness.values())
.map(Enum::name)
.toArray(String[]::new))
+ ".");
}

private Stream<Path> expandConfigPrivate(@Name("start") Object start, @Name("config") Map<String, Object> config) {
Expand Down
17 changes: 17 additions & 0 deletions core/src/test/java/apoc/path/ExpandPathTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static apoc.util.Util.labelStrings;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import apoc.util.MapUtil;
Expand Down Expand Up @@ -696,6 +697,22 @@ public void testLabelWithTwoDots() {
});
}

@Test
public void testShouldFailOnInvalidUniqueness() {
String statement =
"""
MATCH (k:Person {name:'Keanu Reeves'})
CALL apoc.path.expandConfig(k, {uniqueness: 'NODE_GLOBALS'})
YIELD path
RETURN path
""";

RuntimeException e = assertThrows(RuntimeException.class, () -> TestUtil.testCall(db, statement, (res) -> {}));
String expectedMessage =
"Failed to invoke procedure `apoc.path.expandConfig`: Caused by: java.lang.RuntimeException: Invalid uniqueness: 'NODE_GLOBALS'. Must be one of: NODE_GLOBAL, NODE_PATH, NODE_RECENT, NODE_LEVEL, RELATIONSHIP_GLOBAL, RELATIONSHIP_PATH, RELATIONSHIP_RECENT, RELATIONSHIP_LEVEL, NONE.";
assertEquals(expectedMessage, e.getMessage());
}

private void specialCharAssertions(Result result) {
Map<String, Object> row = result.next();
assertSinglePath(row);
Expand Down

0 comments on commit 9158435

Please sign in to comment.