You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by gi...@apache.org on 2026/09/05 13:46:58 UTC

(seatunnel) 01/01: [Improve][Zeta] Return the failure message instead of a stack trace from REST errors (#12070)

This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/dev/pr-12070-0badccfbe28033f1f770609f2e5389211b8a8917
in repository https://gitbox.apache.org/repos/asf/seatunnel.git

commit 0b559fbf7bb0b64f2c6840d2f167ee599507d01b
Author: SEZ <20...@users.noreply.github.com>
AuthorDate: Sat Sep 5 13:46:33 2026 +0000

    [Improve][Zeta] Return the failure message instead of a stack trace from REST errors (#12070)
---
 .../rest/filter/ExceptionHandlingFilter.java       |  4 +-
 .../rest/filter/ExceptionHandlingFilterTest.java   | 80 ++++++++++++++++++++++
 2 files changed, 83 insertions(+), 1 deletion(-)

diff --git a/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/filter/ExceptionHandlingFilter.java b/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/filter/ExceptionHandlingFilter.java
index 21a2383fba..0b1d55208b 100644
--- a/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/filter/ExceptionHandlingFilter.java
+++ b/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/filter/ExceptionHandlingFilter.java
@@ -65,7 +65,9 @@ public class ExceptionHandlingFilter implements Filter {
         response.setContentType("application/json;charset=UTF-8");
 
         ErrResponse errorResponse = new ErrResponse();
-        errorResponse.setMessage(ExceptionUtils.getStackTrace(e));
+        // The type and message of the failure are what a caller can act on. The frames behind it
+        // only describe the internals of this node, and they are logged below either way.
+        errorResponse.setMessage(ExceptionUtils.getMessage(e));
         errorResponse.setStatus("fail");
 
         String jsonResponse = objectMapper.writeValueAsString(errorResponse);
diff --git a/seatunnel-engine/seatunnel-engine-server/src/test/java/org/apache/seatunnel/engine/server/rest/filter/ExceptionHandlingFilterTest.java b/seatunnel-engine/seatunnel-engine-server/src/test/java/org/apache/seatunnel/engine/server/rest/filter/ExceptionHandlingFilterTest.java
new file mode 100644
index 0000000000..726e1c4aa1
--- /dev/null
+++ b/seatunnel-engine/seatunnel-engine-server/src/test/java/org/apache/seatunnel/engine/server/rest/filter/ExceptionHandlingFilterTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.seatunnel.engine.server.rest.filter;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/** Covers the error payload the REST filter writes when a request fails. */
+public class ExceptionHandlingFilterTest {
+
+    @Test
+    void testErrorResponseKeepsTheMessageAndDropsTheStackFrames() throws Exception {
+        StringWriter body = new StringWriter();
+        HttpServletResponse response = mock(HttpServletResponse.class);
+        when(response.getWriter()).thenReturn(new PrintWriter(body));
+
+        ExceptionHandlingFilter filter = new ExceptionHandlingFilter();
+        filter.init(null);
+        FilterChain chain =
+                (req, resp) -> {
+                    throw new IllegalArgumentException("Job id is required");
+                };
+
+        filter.doFilter(mock(ServletRequest.class), response, chain);
+
+        verify(response).setStatus(HttpServletResponse.SC_BAD_REQUEST);
+        String json = body.toString();
+        Assertions.assertTrue(json.contains("Job id is required"), json);
+        Assertions.assertTrue(json.contains("IllegalArgumentException"), json);
+        Assertions.assertTrue(json.contains("\"status\":\"fail\""), json);
+        Assertions.assertFalse(json.contains("at org.apache.seatunnel"), json);
+    }
+
+    @Test
+    void testUnexpectedFailureIsReportedAsAServerErrorWithoutStackFrames() throws Exception {
+        StringWriter body = new StringWriter();
+        HttpServletResponse response = mock(HttpServletResponse.class);
+        when(response.getWriter()).thenReturn(new PrintWriter(body));
+
+        ExceptionHandlingFilter filter = new ExceptionHandlingFilter();
+        filter.init(null);
+        FilterChain chain =
+                (req, resp) -> {
+                    throw new IllegalStateException("cluster is not ready");
+                };
+
+        filter.doFilter(mock(ServletRequest.class), response, chain);
+
+        verify(response).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+        String json = body.toString();
+        Assertions.assertTrue(json.contains("cluster is not ready"), json);
+        Assertions.assertFalse(json.contains("at org.apache.seatunnel"), json);
+    }
+}