Include exception message in stack trace.
This commit is contained in:
parent
09a3391761
commit
eaf72b194f
3 changed files with 35 additions and 2 deletions
|
@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.util;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.signal.core.util.ExceptionUtil;
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
|
@ -20,7 +21,7 @@ public class SignalUncaughtExceptionHandler implements Thread.UncaughtExceptionH
|
|||
|
||||
@Override
|
||||
public void uncaughtException(@NonNull Thread t, @NonNull Throwable e) {
|
||||
if (e instanceof OnErrorNotImplementedException) {
|
||||
if (e instanceof OnErrorNotImplementedException && e.getCause() != null) {
|
||||
e = e.getCause();
|
||||
}
|
||||
|
||||
|
@ -28,6 +29,6 @@ public class SignalUncaughtExceptionHandler implements Thread.UncaughtExceptionH
|
|||
SignalStore.blockUntilAllWritesFinished();
|
||||
Log.blockUntilAllWritesFinished();
|
||||
ApplicationDependencies.getJobManager().flush();
|
||||
originalHandler.uncaughtException(t, e);
|
||||
originalHandler.uncaughtException(t, ExceptionUtil.joinStackTraceAndMessage(e));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package org.signal.core.util;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.logsubmit.util.Scrubber;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
|
@ -50,6 +52,36 @@ public final class ExceptionUtil {
|
|||
return combinedTrace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Joins the stack trace with the exception's {@link Throwable#getMessage()}.
|
||||
*
|
||||
* The resulting stack trace will look like this:
|
||||
*
|
||||
* Original
|
||||
* Stack
|
||||
* Trace
|
||||
* [[ ↑↑ Original Trace ↑↑ ]]
|
||||
* [[ ↓↓ Exception Message ↓↓ ]]
|
||||
* Exception Message
|
||||
*
|
||||
* @return The provided original exception, for convenience.
|
||||
*/
|
||||
public static @NonNull <E extends Throwable> E joinStackTraceAndMessage(@NonNull E original) {
|
||||
StackTraceElement[] originalTrace = original.getStackTrace();
|
||||
StackTraceElement[] combinedTrace = new StackTraceElement[originalTrace.length + 3];
|
||||
|
||||
System.arraycopy(originalTrace, 0, combinedTrace, 0, originalTrace.length);
|
||||
|
||||
CharSequence message = Scrubber.scrub(original.getMessage() != null ? original.getMessage() : "null");
|
||||
|
||||
combinedTrace[originalTrace.length] = new StackTraceElement("[[ ↑↑ Original Trace ↑↑ ]]", "", "", 0);
|
||||
combinedTrace[originalTrace.length + 1] = new StackTraceElement("[[ ↓↓ Exception Message ↓↓ ]]", "", "", 0);
|
||||
combinedTrace[originalTrace.length + 2] = new StackTraceElement(message.toString(), "", "", 0);
|
||||
|
||||
original.setStackTrace(combinedTrace);
|
||||
return original;
|
||||
}
|
||||
|
||||
public static @NonNull String convertThrowableToString(@NonNull Throwable throwable) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
throwable.printStackTrace(new PrintStream(outputStream));
|
||||
|
|
Loading…
Add table
Reference in a new issue