Skip to content

Commit 54a3fe8

Browse files
committed
Merge branch 'main' into feature/simplified-insights
2 parents 0ea9980 + abe4b56 commit 54a3fe8

File tree

15 files changed

+285
-178
lines changed

15 files changed

+285
-178
lines changed

ide-common/src/main/java/org/digma/intellij/plugin/analytics/AnalyticsService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,9 +616,9 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
616616
// will not explode the logs, so we don't see all the exceptions in the log as they happen.
617617
//this message will explode the idea.log if user has digma trace logging on and no backend running,
618618
// which shouldn't happen, users should not have digma trace logging on all the time.
619-
var realCause = ExceptionUtils.findFirstRealExceptionCause(e);
620-
exception = Objects.requireNonNullElse(realCause, e);
621-
Log.log(LOGGER::trace, "got exception in AnalyticsService {}", Objects.requireNonNullElse(realCause, e));
619+
var realCause = ExceptionUtils.findRootCause(e);
620+
exception = realCause;
621+
Log.log(LOGGER::trace, "got exception in AnalyticsService {}", realCause);
622622

623623

624624
if (methodsThatShouldNotChangeConnectionStatus.contains(method.getName())) {

ide-common/src/main/java/org/digma/intellij/plugin/common/ExceptionUtils.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.digma.intellij.plugin.common;
22

3+
import com.google.common.base.Throwables;
34
import org.digma.intellij.plugin.analytics.*;
45
import org.jetbrains.annotations.*;
56

@@ -8,7 +9,7 @@
89
import java.lang.reflect.*;
910
import java.net.*;
1011
import java.net.http.*;
11-
import java.util.*;
12+
import java.util.List;
1213

1314
public class ExceptionUtils {
1415

@@ -55,31 +56,38 @@ public static Throwable findFirstNonWrapperException(@NotNull Throwable throwabl
5556
return cause;
5657
}
5758

58-
@Nullable
59-
public static Throwable findFirstRealExceptionCause(@NotNull Throwable throwable) {
60-
Throwable cause = throwable;
61-
while (cause instanceof InvocationTargetException || cause instanceof UndeclaredThrowableException) {
6259

63-
cause = cause.getCause();
64-
//special treatment for AnalyticsProviderException, AnalyticsProviderException.cause may be null
65-
if (cause instanceof AnalyticsProviderException analyticsProviderException && analyticsProviderException.getCause() != null) {
66-
cause = analyticsProviderException.getCause();
67-
}
60+
@NotNull
61+
public static Throwable findRootCause(@NotNull Throwable throwable) {
62+
63+
try {
64+
return Throwables.getRootCause(throwable);
65+
} catch (Throwable e) {
66+
return throwable;
6867
}
6968

70-
return cause;
69+
//this code finds root cause without throwing exception in loop like guava does
70+
// Throwable cause = throwable;
71+
// Throwable latestNonNullCause = null;
72+
// while (cause != null && cause != latestNonNullCause) {
73+
// latestNonNullCause = cause;
74+
// cause = cause.getCause();
75+
// }
76+
//
77+
// return latestNonNullCause;
7178
}
7279

80+
7381
@NotNull
74-
public static Class<? extends Throwable> findFirstRealExceptionCauseType(@NotNull Throwable throwable) {
75-
var realCause = findFirstRealExceptionCause(throwable);
76-
return Objects.requireNonNullElse(realCause, throwable).getClass();
82+
public static Class<? extends Throwable> findRootCauseType(@NotNull Throwable throwable) {
83+
var realCause = findRootCause(throwable);
84+
return realCause.getClass();
7785
}
7886

7987

8088
@NotNull
81-
public static String findFirstRealExceptionCauseTypeName(@NotNull Throwable throwable) {
82-
return findFirstRealExceptionCauseType(throwable).getName();
89+
public static String findRootCauseTypeName(@NotNull Throwable throwable) {
90+
return findRootCauseType(throwable).getName();
8391
}
8492

8593

@@ -104,8 +112,6 @@ public static Throwable findAuthenticationException(@NotNull Throwable throwable
104112
}
105113

106114

107-
108-
109115
public static boolean isAnyConnectionException(@NotNull Throwable e) {
110116
return isConnectionException(e) || isSslConnectionException(e);
111117
}
@@ -217,8 +223,8 @@ public static boolean isEOFException(@NotNull Throwable e) {
217223
@NotNull
218224
public static String getNonEmptyMessage(@NotNull Throwable exception) {
219225

220-
var realCause = findFirstRealExceptionCause(exception);
221-
if (realCause != null && realCause.getMessage() != null) {
226+
var realCause = findRootCause(exception);
227+
if (realCause.getMessage() != null) {
222228
return realCause.getMessage();
223229
}
224230

ide-common/src/main/kotlin/org/digma/intellij/plugin/analytics/ApiErrorHandler.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import com.intellij.openapi.project.ProjectManager
88
import com.intellij.util.Alarm
99
import org.digma.intellij.plugin.common.DisposableAdaptor
1010
import org.digma.intellij.plugin.common.EDT
11-
import org.digma.intellij.plugin.common.ExceptionUtils
1211
import org.digma.intellij.plugin.common.ExceptionUtils.findConnectException
13-
import org.digma.intellij.plugin.common.ExceptionUtils.findFirstRealExceptionCause
12+
import org.digma.intellij.plugin.common.ExceptionUtils.findRootCause
1413
import org.digma.intellij.plugin.common.ExceptionUtils.findSslException
1514
import org.digma.intellij.plugin.common.ExceptionUtils.getNonEmptyMessage
1615
import org.digma.intellij.plugin.common.ExceptionUtils.isEOFException
@@ -212,20 +211,20 @@ class ApiErrorHandler : DisposableAdaptor {
212211
}
213212
}
214213

215-
fun handleAuthManagerCantRefreshError(throwable: Throwable, project: Project?) {
214+
fun handleAuthManagerCantRefreshError(throwable: Throwable) {
216215
//todo: currently only reporting
217216
Log.warnWithException(logger, throwable, "error in AuthManager {}", throwable)
218217

219218
val message = if (throwable is AuthenticationException) {
220219
throwable.message
221220
} else {
222-
ExceptionUtils.getNonEmptyMessage(throwable)
221+
getNonEmptyMessage(throwable)
223222
}
224223

225224
doForAllProjects { p ->
226225
EDT.ensureEDT {
227226
NotificationUtil.notifyWarning(
228-
project, "<html>Error with Digma backend " + message + ".<br> "
227+
p, "<html>Error with Digma backend " + message + ".<br> "
229228
+ message + ".<br> See logs for details."
230229
)
231230
}
@@ -441,7 +440,7 @@ class ApiErrorHandler : DisposableAdaptor {
441440

442441

443442
fun addIfNewError(e: Exception): Boolean {
444-
val cause = findFirstRealExceptionCause(e)
443+
val cause = findRootCause(e)
445444
val errorName = Objects.requireNonNullElse(cause, e)?.javaClass?.name.toString()
446445
return errors.add(errorName)
447446
}

ide-common/src/main/kotlin/org/digma/intellij/plugin/auth/AuthInfoChangeListener.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.digma.intellij.plugin.auth
22

3-
data class AuthInfo(val userId: String?);
3+
//AuthManager relies on equality of AuthInfo to decide if to fire authInfoChanged event.
4+
// remember that when changing this class
5+
data class AuthInfo(val userId: String?, val accountId: String?)
46

57
fun interface AuthInfoChangeListener {
68
fun authInfoChanged(authInfo: AuthInfo)

0 commit comments

Comments
 (0)