branch-2.1: [opt](paimon)Add suppressed information display #48947 (#48997)

Cherry-picked from #48947

Co-authored-by: wuwenchi <wuwenchi@selectdb.com>
This commit is contained in:
github-actions[bot]
2025-03-22 07:42:45 +08:00
committed by GitHub
parent abc535a9e7
commit 2eed4f3a65
3 changed files with 107 additions and 1 deletions

View File

@ -643,6 +643,26 @@ public class Util {
return rootCause;
}
public static String getRootCauseWithSuppressedMessage(Throwable t) {
String rootCause;
Throwable p = t;
while (p.getCause() != null) {
p = p.getCause();
}
String message = p.getMessage();
if (message == null) {
rootCause = p.getClass().getName();
} else {
rootCause = p.getClass().getName() + ": " + p.getMessage();
}
StringBuilder msg = new StringBuilder(rootCause);
Throwable[] suppressed = p.getSuppressed();
for (int i = 0; i < suppressed.length; i++) {
msg.append(" With suppressed").append("[").append(i).append("]:").append(suppressed[i].getMessage());
}
return msg.toString();
}
// Return the stack of the root cause
public static String getRootCauseStack(Throwable t) {
String rootStack = "unknown";

View File

@ -1034,7 +1034,7 @@ public class StmtExecutor {
} catch (Exception e) {
LOG.warn("execute Exception. {}", context.getQueryIdentifier(), e);
context.getState().setError(ErrorCode.ERR_UNKNOWN_ERROR,
e.getClass().getSimpleName() + ", msg: " + Util.getRootCauseMessage(e));
e.getClass().getSimpleName() + ", msg: " + Util.getRootCauseWithSuppressedMessage(e));
if (parsedStmt instanceof KillStmt) {
// ignore kill stmt execute err(not monitor it)
context.getState().setErrType(QueryState.ErrType.ANALYSIS_ERR);

View File

@ -0,0 +1,86 @@
// 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.doris.common.util;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class UtilTest {
@Test
public void getRootCauseWithSuppressedMessageRootCauseWithMessageNoSuppressed() {
Exception rootCause = new Exception("Root cause message");
Assertions.assertEquals("java.lang.Exception: Root cause message",
Util.getRootCauseWithSuppressedMessage(rootCause));
}
@Test
public void getRootCauseWithSuppressedMessageRootCauseWithMessageWithSuppressed() {
Exception rootCause = new Exception("Root cause message");
rootCause.addSuppressed(new Exception("Suppressed message"));
Assertions.assertEquals(
"java.lang.Exception: Root cause message With suppressed[0]:Suppressed message",
Util.getRootCauseWithSuppressedMessage(rootCause));
}
@Test
public void getRootCauseWithSuppressedMessageRootCauseWithMessageWithMultiSuppressed() {
Exception rootCause = new Exception("Root cause message");
rootCause.addSuppressed(new Exception("Suppressed message"));
rootCause.addSuppressed(new Exception("Suppressed message2"));
Assertions.assertEquals(
"java.lang.Exception: Root cause message"
+ " With suppressed[0]:Suppressed message"
+ " With suppressed[1]:Suppressed message2",
Util.getRootCauseWithSuppressedMessage(rootCause));
}
@Test
public void getRootCauseWithSuppressedMessageRootCauseWithoutMessageNoSuppressed() {
Exception rootCause = new Exception();
Assertions.assertEquals("java.lang.Exception", Util.getRootCauseWithSuppressedMessage(rootCause));
}
@Test
public void getRootCauseWithSuppressedMessageRootCauseWithoutMessageWithSuppressed() {
Exception rootCause = new Exception();
rootCause.addSuppressed(new Exception("Suppressed message"));
Assertions.assertEquals(
"java.lang.Exception With suppressed[0]:Suppressed message",
Util.getRootCauseWithSuppressedMessage(rootCause));
}
@Test
public void getRootCauseWithSuppressedMessageChainedExceptionWithChainedSuppressed() {
Exception rootCause = new Exception("Root cause message");
Exception chainedException = new Exception("Chained exception", rootCause);
chainedException.addSuppressed(new Exception("Suppressed message"));
Assertions.assertEquals("java.lang.Exception: Root cause message",
Util.getRootCauseWithSuppressedMessage(chainedException));
}
@Test
public void getRootCauseWithSuppressedMessageChainedExceptionWithCauseSuppressed() {
Exception rootCause = new Exception("Root cause message");
Exception chainedException = new Exception("Chained exception", rootCause);
rootCause.addSuppressed(new Exception("Suppressed message"));
Assertions.assertEquals(
"java.lang.Exception: Root cause message With suppressed[0]:Suppressed message",
Util.getRootCauseWithSuppressedMessage(chainedException));
}
}