mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
print attachments when logging exceptions in tests
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package com.intellij.testFramework;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.diagnostic.DefaultLogger;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -45,6 +46,7 @@ public class LoggedErrorProcessor {
|
||||
|
||||
@SuppressWarnings("UseOfSystemOutOrSystemErr")
|
||||
public void processError(String message, Throwable t, String[] details, @NotNull Logger logger) {
|
||||
message += DefaultLogger.attachmentsToString(t);
|
||||
logger.info(message, t);
|
||||
|
||||
if (myMirrorToStderr) {
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package com.intellij.openapi.diagnostic;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.ExceptionUtil;
|
||||
import com.intellij.util.Function;
|
||||
import org.apache.log4j.Level;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -56,6 +59,7 @@ public class DefaultLogger extends Logger {
|
||||
@SuppressWarnings("UseOfSystemOutOrSystemErr")
|
||||
public void error(String message, @Nullable Throwable t, @NotNull String... details) {
|
||||
t = checkException(t);
|
||||
message += attachmentsToString(t);
|
||||
System.err.println("ERROR: " + message);
|
||||
if (t != null) t.printStackTrace(System.err);
|
||||
if (details.length > 0) {
|
||||
@@ -72,4 +76,22 @@ public class DefaultLogger extends Logger {
|
||||
|
||||
@Override
|
||||
public void setLevel(Level level) { }
|
||||
|
||||
public static String attachmentsToString(Throwable t) {
|
||||
//noinspection ThrowableResultOfMethodCallIgnored
|
||||
Throwable rootCause = ExceptionUtil.getRootCause(t);
|
||||
if (rootCause instanceof ExceptionWithAttachments) {
|
||||
return "\nAttachments:" + StringUtil.join(((ExceptionWithAttachments)rootCause).getAttachments(),
|
||||
new Function<Attachment, String>() {
|
||||
@Override
|
||||
public String fun(Attachment attachment) {
|
||||
return attachment.getPath() + "\n" + attachment.getDisplayText();
|
||||
}
|
||||
},
|
||||
"\n----\n");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user