Skip to content

Commit 30a10e6

Browse files
authored
[opt](paimon)Add suppressed information display (apache#48947)
### What problem does this PR solve? Problem Summary: Some important error messages may be suppressed after caused. If you only look at the caused information, it may be misleading, so the suppressed information is also displayed so that you can have more error information to locate the problem.
1 parent 53a14d0 commit 30a10e6

File tree

3 files changed

+107
-1
lines changed

3 files changed

+107
-1
lines changed

fe/fe-core/src/main/java/org/apache/doris/common/util/Util.java

+20
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,26 @@ public static String getRootCauseMessage(Throwable t) {
658658
return rootCause;
659659
}
660660

661+
public static String getRootCauseWithSuppressedMessage(Throwable t) {
662+
String rootCause;
663+
Throwable p = t;
664+
while (p.getCause() != null) {
665+
p = p.getCause();
666+
}
667+
String message = p.getMessage();
668+
if (message == null) {
669+
rootCause = p.getClass().getName();
670+
} else {
671+
rootCause = p.getClass().getName() + ": " + p.getMessage();
672+
}
673+
StringBuilder msg = new StringBuilder(rootCause);
674+
Throwable[] suppressed = p.getSuppressed();
675+
for (int i = 0; i < suppressed.length; i++) {
676+
msg.append(" With suppressed").append("[").append(i).append("]:").append(suppressed[i].getMessage());
677+
}
678+
return msg.toString();
679+
}
680+
661681
// Return the stack of the root cause
662682
public static String getRootCauseStack(Throwable t) {
663683
String rootStack = "unknown";

fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ public void executeByLegacy(TUniqueId queryId) throws Exception {
11771177
} catch (Exception e) {
11781178
LOG.warn("execute Exception. {}", context.getQueryIdentifier(), e);
11791179
context.getState().setError(ErrorCode.ERR_UNKNOWN_ERROR,
1180-
e.getClass().getSimpleName() + ", msg: " + Util.getRootCauseMessage(e));
1180+
e.getClass().getSimpleName() + ", msg: " + Util.getRootCauseWithSuppressedMessage(e));
11811181
if (parsedStmt instanceof KillStmt) {
11821182
// ignore kill stmt execute err(not monitor it)
11831183
context.getState().setErrType(QueryState.ErrType.ANALYSIS_ERR);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.doris.common.util;
19+
20+
import org.junit.jupiter.api.Assertions;
21+
import org.junit.jupiter.api.Test;
22+
23+
public class UtilTest {
24+
25+
@Test
26+
public void getRootCauseWithSuppressedMessageRootCauseWithMessageNoSuppressed() {
27+
Exception rootCause = new Exception("Root cause message");
28+
Assertions.assertEquals("java.lang.Exception: Root cause message",
29+
Util.getRootCauseWithSuppressedMessage(rootCause));
30+
}
31+
32+
@Test
33+
public void getRootCauseWithSuppressedMessageRootCauseWithMessageWithSuppressed() {
34+
Exception rootCause = new Exception("Root cause message");
35+
rootCause.addSuppressed(new Exception("Suppressed message"));
36+
Assertions.assertEquals(
37+
"java.lang.Exception: Root cause message With suppressed[0]:Suppressed message",
38+
Util.getRootCauseWithSuppressedMessage(rootCause));
39+
}
40+
41+
@Test
42+
public void getRootCauseWithSuppressedMessageRootCauseWithMessageWithMultiSuppressed() {
43+
Exception rootCause = new Exception("Root cause message");
44+
rootCause.addSuppressed(new Exception("Suppressed message"));
45+
rootCause.addSuppressed(new Exception("Suppressed message2"));
46+
Assertions.assertEquals(
47+
"java.lang.Exception: Root cause message"
48+
+ " With suppressed[0]:Suppressed message"
49+
+ " With suppressed[1]:Suppressed message2",
50+
Util.getRootCauseWithSuppressedMessage(rootCause));
51+
}
52+
53+
@Test
54+
public void getRootCauseWithSuppressedMessageRootCauseWithoutMessageNoSuppressed() {
55+
Exception rootCause = new Exception();
56+
Assertions.assertEquals("java.lang.Exception", Util.getRootCauseWithSuppressedMessage(rootCause));
57+
}
58+
59+
@Test
60+
public void getRootCauseWithSuppressedMessageRootCauseWithoutMessageWithSuppressed() {
61+
Exception rootCause = new Exception();
62+
rootCause.addSuppressed(new Exception("Suppressed message"));
63+
Assertions.assertEquals(
64+
"java.lang.Exception With suppressed[0]:Suppressed message",
65+
Util.getRootCauseWithSuppressedMessage(rootCause));
66+
}
67+
68+
@Test
69+
public void getRootCauseWithSuppressedMessageChainedExceptionWithChainedSuppressed() {
70+
Exception rootCause = new Exception("Root cause message");
71+
Exception chainedException = new Exception("Chained exception", rootCause);
72+
chainedException.addSuppressed(new Exception("Suppressed message"));
73+
Assertions.assertEquals("java.lang.Exception: Root cause message",
74+
Util.getRootCauseWithSuppressedMessage(chainedException));
75+
}
76+
77+
@Test
78+
public void getRootCauseWithSuppressedMessageChainedExceptionWithCauseSuppressed() {
79+
Exception rootCause = new Exception("Root cause message");
80+
Exception chainedException = new Exception("Chained exception", rootCause);
81+
rootCause.addSuppressed(new Exception("Suppressed message"));
82+
Assertions.assertEquals(
83+
"java.lang.Exception: Root cause message With suppressed[0]:Suppressed message",
84+
Util.getRootCauseWithSuppressedMessage(chainedException));
85+
}
86+
}

0 commit comments

Comments
 (0)