diff --git a/src/main/java/com/kri/contact/server/service/async/ListAsyncDownloadService.java b/src/main/java/com/kri/contact/server/service/async/ListAsyncDownloadService.java index c9939b3..3816dd3 100644 --- a/src/main/java/com/kri/contact/server/service/async/ListAsyncDownloadService.java +++ b/src/main/java/com/kri/contact/server/service/async/ListAsyncDownloadService.java @@ -128,7 +128,10 @@ public class ListAsyncDownloadService { context.progress("FILE_READY", null, observer.values(true)); } catch (IOException failure) { discard(result, failure); - throw BusinessException.internalError("LIST_DOWNLOAD_FAILED", "다운로드 파일 생성 중 오류가 발생했습니다."); + var wrapped = BusinessException.internalError("LIST_DOWNLOAD_FAILED", "다운로드 파일 생성 중 오류가 발생했습니다."); + // BusinessException has no public cause-aware factory and initializes its cause to null. + wrapped.addSuppressed(failure); + throw wrapped; } catch (RuntimeException failure) { discard(result, failure); throw failure; diff --git a/src/main/java/com/kri/contact/server/service/async/ListAsyncJobExecutor.java b/src/main/java/com/kri/contact/server/service/async/ListAsyncJobExecutor.java index 3f5c145..4e77641 100644 --- a/src/main/java/com/kri/contact/server/service/async/ListAsyncJobExecutor.java +++ b/src/main/java/com/kri/contact/server/service/async/ListAsyncJobExecutor.java @@ -11,6 +11,7 @@ import com.kri.contact.server.dto.list.async.ListAsyncResultFileDto; import com.kri.contact.server.persistence.entity.TListAsyncJobEntity; import com.kri.contact.server.service.file.ListAsyncResultFileService; import jakarta.annotation.PreDestroy; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -234,9 +235,22 @@ public class ListAsyncJobExecutor implements ApplicationRunner { private static Map failureDetails(Throwable failure) { var causes = new ArrayList>(); var seen = Collections.newSetFromMap(new IdentityHashMap()); - Throwable current = failure; - while (current != null && causes.size() < 8 && seen.add(current)) { + record PendingFailure(Throwable exception, String relation, int parentIndex) {} + var pending = new ArrayDeque(); + pending.add(new PendingFailure(failure, "root", -1)); + boolean truncated = false; + while (!pending.isEmpty() && causes.size() < 8) { + var entry = pending.removeFirst(); + Throwable current = entry.exception(); + if (!seen.add(current)) { + truncated = true; + continue; + } var detail = new LinkedHashMap(); + if (entry.parentIndex() >= 0) { + detail.put("relation", entry.relation()); + detail.put("parentIndex", entry.parentIndex()); + } detail.put("exceptionType", current.getClass().getName()); if (current instanceof BusinessException business) { String code = business.getCode(); @@ -251,10 +265,16 @@ public class ListAsyncJobExecutor implements ApplicationRunner { detail.put("stackTrace", Arrays.stream(current.getStackTrace()).limit(80) .map(frame -> frame.getClassName() + "." + frame.getMethodName() + ":" + frame.getLineNumber()) .toList()); + int parentIndex = causes.size(); causes.add(detail); - current = current.getCause(); + if (current.getCause() != null) { + pending.add(new PendingFailure(current.getCause(), "cause", parentIndex)); + } + for (Throwable suppressed : current.getSuppressed()) { + pending.add(new PendingFailure(suppressed, "suppressed", parentIndex)); + } } - return Map.of("causes", causes, "truncated", current != null); + return Map.of("causes", causes, "truncated", truncated || !pending.isEmpty()); } private final class JobTask implements Runnable {