You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "NateAdere (via GitHub)" <gi...@apache.org> on 2023/03/10 18:28:43 UTC

[GitHub] [cassandra] NateAdere commented on a diff in pull request #2104: Cassandra 17199 - Provide summary of failed SessionInfo's in StreamResultFuture

NateAdere commented on code in PR #2104:
URL: https://github.com/apache/cassandra/pull/2104#discussion_r1132732761


##########
src/java/org/apache/cassandra/streaming/StreamSession.java:
##########
@@ -1340,32 +1338,41 @@ public String toString()
                '}';
     }
 
-    public static Throwable boundStackTrace(Throwable e, int limit)
+    public static StringBuilder boundStackTrace(Throwable e, int limit)
     {
         Set<Throwable> visited = Collections.newSetFromMap(new IdentityHashMap<>());
-        return boundStackTrace(e, limit, visited);
+        StringBuilder out = new StringBuilder();
+        return boundStackTrace(e, limit, visited, out);
     }
 
-    public static Throwable boundStackTrace(Throwable e, int limit, Set<Throwable> visited)
+    public static StringBuilder boundStackTrace(Throwable e, int limit, Set<Throwable> visited, StringBuilder out)
     {
         if (e == null)
-            return e;
+            return null;
 
         if (!visited.add(e))
-            return e;
+            return out.append("[CIRCULAR REFERENCE: ").append(e.getClass().getName()).append(": ").append(e.getMessage()).append("]");
         visited.add(e);
 
         if (e.getStackTrace().length == 0 || e.getStackTrace().length < limit)
         {
-            boundStackTrace(e.getCause(), limit, visited);
-            return e;
+            out.append(e.getClass().getName()).append(": ").append(e.getMessage()).append('\n');
+            boundStackTrace(e.getCause(), limit, visited, out);
+            return out;
         }
 
         StackTraceElement[] stackTrace = e.getStackTrace();
-        StackTraceElement[] limitedStackTrace = Arrays.copyOfRange(stackTrace, 0, limit);
-        e.setStackTrace(limitedStackTrace);
-        boundStackTrace(e.getCause(), limit, visited);
+        StringBuilder stackTraceBuilder = new StringBuilder();
+        stackTraceBuilder.append(e.getClass().getName() + ": " + e.getMessage()).append('\n');
+
+        for (int i = 0; i < limit; i++)
+        {
+            stackTraceBuilder.append('\t').append(stackTrace[i]);
+            if (e.getCause() == null && i == limit - 1) continue;

Review Comment:
   This was added to avoid an extra new line that is added to the last exception when creating a bounded stringbuilder for a nested exception



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org