This is an automated email from the ASF dual-hosted git repository.
jin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hugegraph.git
The following commit(s) were added to refs/heads/master by this push:
new 06097c8a2 refactor(server): allow TinkerPop exceptions in Gremlin resp
(#2987)
06097c8a2 is described below
commit 06097c8a2075575fd0e41a0e2f407700e4438b6f
Author: Uğur Tafralı <[email protected]>
AuthorDate: Fri Apr 10 12:57:05 2026 +0300
refactor(server): allow TinkerPop exceptions in Gremlin resp (#2987)
* fix(api/gremlin): allow TinkerPop exceptions in Gremlin responses
* Address review feedback
---
.../hugegraph/api/gremlin/GremlinQueryAPI.java | 3 +-
.../org/apache/hugegraph/unit/UnitTestSuite.java | 4 ++
.../unit/api/gremlin/GremlinQueryAPITest.java | 63 ++++++++++++++++++++++
3 files changed, 69 insertions(+), 1 deletion(-)
diff --git
a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/gremlin/GremlinQueryAPI.java
b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/gremlin/GremlinQueryAPI.java
index 1f35da5f1..2ab55f584 100644
---
a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/gremlin/GremlinQueryAPI.java
+++
b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/gremlin/GremlinQueryAPI.java
@@ -43,7 +43,8 @@ public class GremlinQueryAPI extends API {
"java.util.concurrent.TimeoutException",
"groovy.lang.",
"org.codehaus.",
- "org.apache.hugegraph."
+ "org.apache.hugegraph.",
+
"org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException"
);
@Context
diff --git
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java
index f9f20ab9e..52bf104b0 100644
---
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java
+++
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java
@@ -19,6 +19,7 @@ package org.apache.hugegraph.unit;
import org.apache.hugegraph.core.RoleElectionStateMachineTest;
import org.apache.hugegraph.unit.api.filter.PathFilterTest;
+import org.apache.hugegraph.unit.api.gremlin.GremlinQueryAPITest;
import org.apache.hugegraph.unit.auth.HugeGraphAuthProxyTest;
import org.apache.hugegraph.unit.cache.CacheManagerTest;
import org.apache.hugegraph.unit.cache.CacheTest;
@@ -81,6 +82,9 @@ import org.junit.runners.Suite;
/* api filter */
PathFilterTest.class,
+ /* api gremlin */
+ GremlinQueryAPITest.class,
+
/* cache */
CacheTest.RamCacheTest.class,
CacheTest.OffheapCacheTest.class,
diff --git
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/gremlin/GremlinQueryAPITest.java
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/gremlin/GremlinQueryAPITest.java
new file mode 100644
index 000000000..94deaf921
--- /dev/null
+++
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/gremlin/GremlinQueryAPITest.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hugegraph.unit.api.gremlin;
+
+import java.lang.reflect.Method;
+
+import org.apache.hugegraph.api.gremlin.GremlinQueryAPI;
+import org.apache.hugegraph.testutil.Assert;
+import org.apache.hugegraph.unit.BaseUnitTest;
+import org.junit.Test;
+
+public class GremlinQueryAPITest extends BaseUnitTest {
+
+ private static boolean matchBadRequest(String exClass) throws Exception {
+ Method m = GremlinQueryAPI.class.getDeclaredMethod(
+ "matchBadRequestException", String.class);
+ m.setAccessible(true);
+ return (boolean) m.invoke(null, exClass);
+ }
+
+ @Test
+ public void testMatchBadRequestExceptionWithTinkerpop() throws Exception {
+ Assert.assertTrue(matchBadRequest(
+
"org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException"));
+ }
+
+ @Test
+ public void testMatchBadRequestExceptionWithAuthExceptions() throws
Exception {
+ Assert.assertFalse(matchBadRequest(
+
"org.apache.tinkerpop.gremlin.server.auth.AuthenticationException"));
+ Assert.assertFalse(matchBadRequest(
+
"org.apache.tinkerpop.gremlin.server.authz.AuthorizationException"));
+ }
+
+ @Test
+ public void testMatchBadRequestExceptionWithHugegraph() throws Exception {
+
Assert.assertTrue(matchBadRequest("org.apache.hugegraph.exception.NotFoundException"));
+
Assert.assertTrue(matchBadRequest("java.lang.IllegalArgumentException"));
+
Assert.assertTrue(matchBadRequest("groovy.lang.MissingPropertyException"));
+ }
+
+ @Test
+ public void testMatchBadRequestExceptionWithOther() throws Exception {
+ Assert.assertFalse(matchBadRequest(null));
+ Assert.assertFalse(matchBadRequest("java.lang.NullPointerException"));
+ Assert.assertFalse(matchBadRequest("java.io.IOException"));
+ }
+}