001/**
002 * Copyright (c) 2025-2026, Michael Yang 杨福海 (fuhai999@gmail.com).
003 * <p>
004 * Licensed under the GNU Lesser General Public License (LGPL) ,Version 3.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * <p>
008 * http://www.gnu.org/licenses/lgpl-3.0.txt
009 * <p>
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package dev.tinyflow.core.chain;
017
018import java.io.PrintWriter;
019import java.io.Serializable;
020import java.io.StringWriter;
021
022public class ExceptionSummary implements Serializable {
023
024    private String exceptionClass;
025    private String message;
026    private String stackTrace;
027
028    private String rootCauseClass;
029    private String rootCauseMessage;
030
031    private String chainId;
032    private String nodeId;
033
034    private String errorCode; // 可选
035
036    private long timestamp;
037
038    public ExceptionSummary(Throwable error) {
039        this.exceptionClass = error.getClass().getName();
040        this.message = error.getMessage();
041        this.stackTrace = getStackTraceAsString(error);
042
043        this.rootCauseClass = error.getClass().getName();
044        this.rootCauseMessage = error.getMessage();
045
046        this.timestamp = System.currentTimeMillis();
047    }
048
049    private static String getStackTraceAsString(Throwable t) {
050        StringWriter sw = new StringWriter();
051        PrintWriter pw = new PrintWriter(sw);
052        t.printStackTrace(pw);
053        return sw.toString();
054    }
055
056    public String getExceptionClass() {
057        return exceptionClass;
058    }
059
060    public void setExceptionClass(String exceptionClass) {
061        this.exceptionClass = exceptionClass;
062    }
063
064    public String getMessage() {
065        return message;
066    }
067
068    public void setMessage(String message) {
069        this.message = message;
070    }
071
072    public String getStackTrace() {
073        return stackTrace;
074    }
075
076    public void setStackTrace(String stackTrace) {
077        this.stackTrace = stackTrace;
078    }
079
080    public String getRootCauseClass() {
081        return rootCauseClass;
082    }
083
084    public void setRootCauseClass(String rootCauseClass) {
085        this.rootCauseClass = rootCauseClass;
086    }
087
088    public String getRootCauseMessage() {
089        return rootCauseMessage;
090    }
091
092    public void setRootCauseMessage(String rootCauseMessage) {
093        this.rootCauseMessage = rootCauseMessage;
094    }
095
096    public String getChainId() {
097        return chainId;
098    }
099
100    public void setChainId(String chainId) {
101        this.chainId = chainId;
102    }
103
104    public String getNodeId() {
105        return nodeId;
106    }
107
108    public void setNodeId(String nodeId) {
109        this.nodeId = nodeId;
110    }
111
112    public String getErrorCode() {
113        return errorCode;
114    }
115
116    public void setErrorCode(String errorCode) {
117        this.errorCode = errorCode;
118    }
119
120    public long getTimestamp() {
121        return timestamp;
122    }
123
124    public void setTimestamp(long timestamp) {
125        this.timestamp = timestamp;
126    }
127}
128