support first-class exception attachments with stack traces

This commit is contained in:
peter
2016-04-01 14:27:24 +02:00
parent e0e5ef5655
commit c66bfeec60
4 changed files with 10 additions and 8 deletions
@@ -18,7 +18,6 @@ package com.intellij.openapi.project;
import com.intellij.openapi.diagnostic.Attachment;
import com.intellij.openapi.diagnostic.ExceptionWithAttachments;
import com.intellij.openapi.util.Computable;
import com.intellij.util.ExceptionUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -68,6 +67,6 @@ public class IndexNotReadyException extends RuntimeException implements Exceptio
public Attachment[] getAttachments() {
return myStartTrace == null
? Attachment.EMPTY_ARRAY
: new Attachment[]{new Attachment("indexingStart.trace", ExceptionUtil.getThrowableText(myStartTrace))};
: new Attachment[]{new Attachment("indexingStart", myStartTrace)};
}
}
@@ -27,7 +27,6 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.stubs.PsiFileStub;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.util.ExceptionUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -80,8 +79,8 @@ public class PsiInvalidElementAccessException extends RuntimeException implement
myDiagnostic = Attachment.EMPTY_ARRAY;
}
else {
String diagnostic = trace instanceof Throwable ? ExceptionUtil.getThrowableText((Throwable)trace) : trace.toString();
myDiagnostic = new Attachment[]{new Attachment("diagnostic.txt", diagnostic)};
myDiagnostic = new Attachment[]{trace instanceof Throwable ? new Attachment("invalidation", (Throwable)trace)
: new Attachment("diagnostic.txt", trace.toString())};
}
}
finally {
@@ -17,6 +17,7 @@ package com.intellij.openapi.diagnostic;
import com.intellij.openapi.vfs.CharsetToolkit;
import com.intellij.util.Base64Converter;
import com.intellij.util.ExceptionUtil;
import com.intellij.util.PathUtilRt;
import org.jetbrains.annotations.NotNull;
@@ -39,6 +40,10 @@ public class Attachment {
myDisplayText = displayText;
}
public Attachment(@NotNull String name, @NotNull Throwable throwable) {
this(name + ".trace", ExceptionUtil.getThrowableText(throwable));
}
@NotNull
public static byte[] getBytes(@NotNull String content) {
return content.getBytes(CharsetToolkit.UTF8_CHARSET);
@@ -19,7 +19,6 @@ import com.intellij.openapi.diagnostic.Attachment;
import com.intellij.openapi.diagnostic.ExceptionWithAttachments;
import com.intellij.openapi.util.objectTree.ThrowableInterner;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ExceptionUtil;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -105,10 +104,10 @@ public class TraceableDisposable {
public Attachment[] getAttachments() {
List<Attachment> answer = ContainerUtil.newSmartList();
if (CREATE_TRACE != null) {
answer.add(new Attachment("creation.trace", ExceptionUtil.getThrowableText(CREATE_TRACE)));
answer.add(new Attachment("creation", CREATE_TRACE));
}
if (KILL_TRACE != null) {
answer.add(new Attachment("kill.trace", ExceptionUtil.getThrowableText(KILL_TRACE)));
answer.add(new Attachment("kill", KILL_TRACE));
}
return answer.toArray(Attachment.EMPTY_ARRAY);
}