Skip to content

Commit 2daec05

Browse files
committed
Improve obscure invalid identifier error message
1 parent 546c866 commit 2daec05

File tree

5 files changed

+73
-5
lines changed

5 files changed

+73
-5
lines changed

graph-projection-api/src/main/java/org/neo4j/gds/ElementIdentifier.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public abstract class ElementIdentifier {
3030

3131
public final @NotNull String name;
3232

33-
ElementIdentifier(@NotNull String name) {
33+
ElementIdentifier(@NotNull String name, String type) {
3434
if (name.equals(ElementProjection.PROJECT_ALL)) {
35-
throw new IllegalArgumentException("name cannot be `*`");
35+
throw new IllegalArgumentException(type + " cannot be `*`");
3636
} else if (StringFormatting.isEmpty(name)) {
37-
throw new IllegalArgumentException("name cannot be empty");
37+
throw new IllegalArgumentException(type + " cannot be empty");
3838
}
3939
this.name = name;
4040
}

graph-projection-api/src/main/java/org/neo4j/gds/NodeLabel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class NodeLabel extends ElementIdentifier {
3030
public static final NodeLabel ALL_NODES = NodeLabel.of("__ALL__");
3131

3232
public NodeLabel(String name) {
33-
super(name);
33+
super(name, "Node label");
3434
}
3535

3636
@Override

graph-projection-api/src/main/java/org/neo4j/gds/RelationshipType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class RelationshipType extends ElementIdentifier {
3030
public static final RelationshipType ALL_RELATIONSHIPS = RelationshipType.of("__ALL__");
3131

3232
public RelationshipType(String name) {
33-
super(name);
33+
super(name, "Relationship type");
3434
}
3535

3636
@Override
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds;
21+
22+
import org.junit.jupiter.api.Test;
23+
24+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
25+
26+
class NodeLabelTest {
27+
28+
@Test
29+
void failOnInvalidName() {
30+
assertThatThrownBy(() -> new NodeLabel("")).isInstanceOf(IllegalArgumentException.class)
31+
.hasMessageMatching("Node label cannot be empty");
32+
}
33+
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds;
21+
22+
import org.junit.jupiter.api.Test;
23+
24+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
25+
26+
class RelationshipTypeTest {
27+
28+
@Test
29+
void failOnInvalidName() {
30+
assertThatThrownBy(() -> new RelationshipType("")).isInstanceOf(IllegalArgumentException.class)
31+
.hasMessageMatching("Relationship type cannot be empty");
32+
}
33+
34+
}

0 commit comments

Comments
 (0)