Przeglądaj źródła

Merge pull request #593 from greboid/dev2

Remove error events and tidy up error management.
pull/594/head
Chris Smith 9 lat temu
rodzic
commit
a4da1ff9f5

+ 7
- 2
src/com/dmdirc/Main.java Wyświetl plik

@@ -37,6 +37,7 @@ import com.dmdirc.interfaces.ui.UIController;
37 37
 import com.dmdirc.logger.DMDircExceptionHandler;
38 38
 import com.dmdirc.logger.ModeAliasReporter;
39 39
 import com.dmdirc.logger.ProgramErrorAppender;
40
+import com.dmdirc.logger.ProgramErrorManager;
40 41
 import com.dmdirc.plugins.CorePluginExtractor;
41 42
 import com.dmdirc.plugins.PluginManager;
42 43
 import com.dmdirc.plugins.Service;
@@ -98,6 +99,7 @@ public class Main {
98 99
     /** Mode alias reporter to use. */
99 100
     private final ModeAliasReporter reporter;
100 101
     private final ServiceManager serviceManager;
102
+    private final ProgramErrorManager errorManager;
101 103
 
102 104
     static {
103 105
         // TODO: Can this go in a Dagger module?
@@ -107,6 +109,7 @@ public class Main {
107 109
         context.reset();
108 110
     }
109 111
 
112
+
110 113
     /**
111 114
      * Creates a new instance of {@link Main}.
112 115
      */
@@ -124,7 +127,8 @@ public class Main {
124 127
             final DMDircMBassador eventBus,
125 128
             final Set<CommandDetails> commands,
126 129
             final ModeAliasReporter reporter,
127
-            final ServiceManager serviceManager) {
130
+            final ServiceManager serviceManager,
131
+            final ProgramErrorManager errorManager) {
128 132
         this.identityManager = identityManager;
129 133
         this.connectionManager = connectionManager;
130 134
         this.commandLineParser = commandLineParser;
@@ -138,6 +142,7 @@ public class Main {
138 142
         this.commands = commands;
139 143
         this.reporter = reporter;
140 144
         this.serviceManager = serviceManager;
145
+        this.errorManager = errorManager;
141 146
     }
142 147
 
143 148
     /**
@@ -278,7 +283,7 @@ public class Main {
278 283
         // TODO: Add a normal logging thing, with or without runtime switching.
279 284
         final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
280 285
         final ProgramErrorAppender appender = new ProgramErrorAppender();
281
-        appender.setEventBus(eventBus);
286
+        appender.setProgramErrorManager(errorManager);
282 287
         appender.setContext(context);
283 288
         appender.setName("Error Logger");
284 289
         appender.start();

+ 0
- 37
src/com/dmdirc/events/AppErrorEvent.java Wyświetl plik

@@ -1,37 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-package com.dmdirc.events;
24
-
25
-import com.dmdirc.logger.ErrorLevel;
26
-
27
-/**
28
- * Event class for app errors.
29
- */
30
-public class AppErrorEvent extends ErrorEvent {
31
-
32
-    public AppErrorEvent(final ErrorLevel level, final Throwable throwable, final String message,
33
-            final String details) {
34
-        super(level, throwable, message, details);
35
-    }
36
-
37
-}

+ 0
- 37
src/com/dmdirc/events/UserErrorEvent.java Wyświetl plik

@@ -1,37 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-package com.dmdirc.events;
24
-
25
-import com.dmdirc.logger.ErrorLevel;
26
-
27
-/**
28
- * Event class for user errors.
29
- */
30
-public class UserErrorEvent extends ErrorEvent {
31
-
32
-    public UserErrorEvent(final ErrorLevel level, final Throwable throwable, final String message,
33
-            final String details) {
34
-        super(level, throwable, message, details);
35
-    }
36
-
37
-}

+ 7
- 7
src/com/dmdirc/logger/DiskLoggingErrorManager.java Wyświetl plik

@@ -28,9 +28,9 @@ import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
28 28
 import com.dmdirc.config.ConfigBinder;
29 29
 import com.dmdirc.config.ConfigBinding;
30 30
 import com.dmdirc.events.ErrorEvent;
31
+import com.dmdirc.events.ProgramErrorEvent;
31 32
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
32 33
 
33
-import com.google.common.base.Throwables;
34 34
 import com.google.common.collect.Lists;
35 35
 
36 36
 import java.io.IOException;
@@ -96,19 +96,19 @@ public class DiskLoggingErrorManager {
96 96
     }
97 97
 
98 98
     @Handler
99
-    void handleErrorEvent(final ErrorEvent error) {
99
+    void handleErrorEvent(final ProgramErrorEvent error) {
100 100
         if (directoryError || !logging) {
101 101
             return;
102 102
         }
103
-        final String logName = error.getTimestamp() + "-" + error.getLevel();
103
+        final String logName = error.getTimestamp() + "-" + error.getError().getLevel();
104 104
         final Path errorFile = errorsDirectory.resolve(logName + ".log");
105 105
         final List<String> data = Lists
106 106
                 .newArrayList("Date: " + new Date(error.getTimestamp()),
107
-                        "Level: " + error.getLevel(),
108
-                        "Description: " + error.getMessage(),
107
+                        "Level: " + error.getError().getLevel(),
108
+                        "Description: " + error.getError().getMessage(),
109 109
                         "Details: ");
110
-        Arrays.stream(Throwables.getStackTraceAsString(error.getThrowable()).split("\n"))
111
-                .forEach(data::add);
110
+        error.getError().getThrowableAsString()
111
+                .ifPresent(s -> Arrays.stream(s.split("\n")).forEach(data::add));
112 112
         try {
113 113
             Files.write(errorFile, data, Charset.forName("UTF-8"));
114 114
         } catch (IOException ex) {

+ 1
- 1
src/com/dmdirc/logger/ErrorReportingRunnable.java Wyświetl plik

@@ -45,7 +45,7 @@ public class ErrorReportingRunnable implements Runnable {
45 45
     public void run() {
46 46
         error.setReportStatus(ErrorReportStatus.SENDING);
47 47
         sentryErrorReporter.sendException(error.getMessage(), error.getLevel(), error.getDate(),
48
-                error.getThrowable(), error.getDetails());
48
+                error.getThrowable());
49 49
         error.setReportStatus(ErrorReportStatus.FINISHED);
50 50
     }
51 51
 

+ 28
- 49
src/com/dmdirc/logger/ProgramError.java Wyświetl plik

@@ -26,14 +26,14 @@ import com.dmdirc.DMDircMBassador;
26 26
 import com.dmdirc.events.ProgramErrorStatusEvent;
27 27
 
28 28
 import com.google.common.base.MoreObjects;
29
-import com.google.common.collect.Lists;
29
+import com.google.common.base.Throwables;
30 30
 
31 31
 import java.io.Serializable;
32
-import java.util.Collections;
33 32
 import java.util.Date;
34
-import java.util.List;
35 33
 import java.util.Objects;
34
+import java.util.Optional;
36 35
 
36
+import javax.annotation.Nonnull;
37 37
 import javax.annotation.Nullable;
38 38
 
39 39
 import static com.google.common.base.Preconditions.checkNotNull;
@@ -50,15 +50,11 @@ public class ProgramError implements Serializable {
50 50
     /** Error message. */
51 51
     private final String message;
52 52
     /** Underlying exception. */
53
-    private final Throwable exception;
54
-    /** The trace for this exception. */
55
-    private final List<String> trace;
56
-    /** Underlying details message. */
57
-    private final String details;
53
+    private final Optional<Throwable> exception;
58 54
     /** Date/time error first occurred. */
59
-    private final Date firstDate;
55
+    private final Date date;
60 56
     /** The eventbus to post status changes to. */
61
-    private final DMDircMBassador eventBus;
57
+    private final Optional<DMDircMBassador> eventBus;
62 58
     /** Is this an application error? */
63 59
     private final boolean appError;
64 60
     /** Error report Status. */
@@ -72,29 +68,27 @@ public class ProgramError implements Serializable {
72 68
      * @param level     Error level
73 69
      * @param message   Error message
74 70
      * @param exception The exception that caused the error, if any.
75
-     * @param trace     The textual trace for this error
76
-     * @param details   The detailed cause of the error, if any.
77 71
      * @param date      Error time and date
78 72
      * @param eventBus  The event bus to post status changes to
79 73
      */
80
-    public ProgramError(final ErrorLevel level, final String message,
74
+    public ProgramError(
75
+            @Nonnull final ErrorLevel level,
76
+            @Nonnull final String message,
81 77
             @Nullable final Throwable exception,
82
-            final Iterable<String> trace,
83
-            @Nullable final String details,
84
-            final Date date,
85
-            final DMDircMBassador eventBus,
78
+            @Nonnull final Date date,
79
+            @Nullable final DMDircMBassador eventBus,
86 80
             final boolean appError) {
87 81
         checkNotNull(level);
82
+        checkNotNull(message);
83
+        checkNotNull(level);
88 84
         checkNotNull(date);
89 85
 
90 86
         this.level = level;
91 87
         this.message = message;
92
-        this.exception = exception;
93
-        this.trace = Lists.newArrayList(trace);
94
-        this.details = details;
95
-        this.firstDate = (Date) date.clone();
88
+        this.exception = Optional.ofNullable(exception);
89
+        this.date = (Date) date.clone();
96 90
         this.reportStatus = ErrorReportStatus.WAITING;
97
-        this.eventBus = eventBus;
91
+        this.eventBus = Optional.ofNullable(eventBus);
98 92
         this.appError = appError;
99 93
     }
100 94
 
@@ -116,21 +110,12 @@ public class ProgramError implements Serializable {
116 110
         return message;
117 111
     }
118 112
 
119
-    public String getDetails() {
120
-        return details;
121
-    }
122
-
123
-    public Throwable getThrowable() {
113
+    public Optional<Throwable> getThrowable() {
124 114
         return exception;
125 115
     }
126 116
 
127
-    /**
128
-     * Returns this errors trace.
129
-     *
130
-     * @return Error trace
131
-     */
132
-    public List<String> getTrace() {
133
-        return Collections.unmodifiableList(trace);
117
+    public Optional<String> getThrowableAsString() {
118
+        return exception.map(Throwables::getStackTraceAsString);
134 119
     }
135 120
 
136 121
     /**
@@ -139,7 +124,7 @@ public class ProgramError implements Serializable {
139 124
      * @return Error time
140 125
      */
141 126
     public Date getDate() {
142
-        return (Date) firstDate.clone();
127
+        return (Date) date.clone();
143 128
     }
144 129
 
145 130
     /**
@@ -159,7 +144,7 @@ public class ProgramError implements Serializable {
159 144
     public void setReportStatus(final ErrorReportStatus newStatus) {
160 145
         if (newStatus != null && reportStatus != newStatus) {
161 146
             reportStatus = newStatus;
162
-            eventBus.publishAsync(new ProgramErrorStatusEvent(this));
147
+            eventBus.ifPresent(e -> e.publishAsync(new ProgramErrorStatusEvent(this)));
163 148
         }
164 149
     }
165 150
 
@@ -199,24 +184,18 @@ public class ProgramError implements Serializable {
199 184
 
200 185
     @Override
201 186
     public boolean equals(final Object obj) {
202
-        if (obj == null) {
203
-            return false;
204
-        }
205
-
206
-        if (getClass() != obj.getClass()) {
207
-            return false;
187
+        if (obj instanceof ProgramError) {
188
+            final ProgramError other = (ProgramError) obj;
189
+            return Objects.equals(getLevel(), other.getLevel()) &&
190
+                    Objects.equals(getMessage(), other.getMessage()) &&
191
+                    Objects.equals(getThrowable(), other.getThrowable());
208 192
         }
209
-
210
-        final ProgramError other = (ProgramError) obj;
211
-        return Objects.equals(getLevel(), other.getLevel())
212
-                && Objects.equals(getMessage(), other.getMessage())
213
-                && Objects.equals(getThrowable(), other.getThrowable())
214
-                && Objects.equals(getDetails(), other.getDetails());
193
+        return false;
215 194
     }
216 195
 
217 196
     @Override
218 197
     public int hashCode() {
219
-        return Objects.hash(level, message, exception, details);
198
+        return Objects.hash(level, message, exception);
220 199
     }
221 200
 
222 201
 }

+ 6
- 32
src/com/dmdirc/logger/ProgramErrorAppender.java Wyświetl plik

@@ -22,33 +22,20 @@
22 22
 
23 23
 package com.dmdirc.logger;
24 24
 
25
-import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.events.AppErrorEvent;
27
-import com.dmdirc.events.UserErrorEvent;
28
-import com.dmdirc.logger.ErrorLevel;
29
-import com.dmdirc.logger.ProgramError;
30
-
31 25
 import ch.qos.logback.classic.spi.ILoggingEvent;
32 26
 import ch.qos.logback.core.AppenderBase;
33 27
 
34
-import static com.dmdirc.util.LogUtils.APP_ERROR;
35
-import static com.dmdirc.util.LogUtils.FATAL_APP_ERROR;
36
-import static com.dmdirc.util.LogUtils.FATAL_USER_ERROR;
37
-import static com.dmdirc.util.LogUtils.USER_ERROR;
38
-import static com.dmdirc.util.LogUtils.getErrorLevel;
39
-import static com.dmdirc.util.LogUtils.getThrowable;
40
-
41 28
 /**
42 29
  * Converts log states into {@link ProgramError}s so they can be displayed to the user.
43 30
  */
44 31
 public class ProgramErrorAppender extends AppenderBase<ILoggingEvent> {
45 32
 
46
-    private DMDircMBassador eventBus;
33
+    private ProgramErrorManager errorManager;
47 34
 
48 35
     @Override
49 36
     public void start() {
50
-        if (eventBus == null) {
51
-            addError("No eventBus set for the appender named ["+ name +"].");
37
+        if (errorManager == null) {
38
+            addError("No error manager set for the appender named ["+ name +"].");
52 39
             return;
53 40
         }
54 41
         super.start();
@@ -59,23 +46,10 @@ public class ProgramErrorAppender extends AppenderBase<ILoggingEvent> {
59 46
         if (eventObject.getMarker() == null) {
60 47
             return;
61 48
         }
62
-        if (eventObject.getMarker() == APP_ERROR) {
63
-            eventBus.publish(new AppErrorEvent(
64
-                    getErrorLevel(eventObject.getLevel()),
65
-                    getThrowable(eventObject), eventObject.getFormattedMessage(), ""));
66
-        } else if (eventObject.getMarker() == USER_ERROR) {
67
-            eventBus.publish(new UserErrorEvent(getErrorLevel(eventObject.getLevel()),
68
-                    getThrowable(eventObject), eventObject.getFormattedMessage(), ""));
69
-        } else if (eventObject.getMarker() == FATAL_APP_ERROR) {
70
-            eventBus.publish(new AppErrorEvent(ErrorLevel.FATAL, getThrowable(eventObject),
71
-                    eventObject.getFormattedMessage(), ""));
72
-        } else if (eventObject.getMarker() == FATAL_USER_ERROR) {
73
-            eventBus.publish(new UserErrorEvent(ErrorLevel.FATAL, getThrowable(eventObject),
74
-                    eventObject.getFormattedMessage(), ""));
75
-        }
49
+        errorManager.handle(eventObject);
76 50
     }
77 51
 
78
-    public void setEventBus(final DMDircMBassador eventBus) {
79
-        this.eventBus = eventBus;
52
+    public void setProgramErrorManager(final ProgramErrorManager errorManager) {
53
+        this.errorManager = errorManager;
80 54
     }
81 55
 }

+ 1
- 3
src/com/dmdirc/logger/ProgramErrorFactory.java Wyświetl plik

@@ -43,10 +43,8 @@ public class ProgramErrorFactory {
43 43
 
44 44
     public ProgramError create(final ErrorLevel level, final String message,
45 45
             @Nullable final Throwable exception,
46
-            final Iterable<String> trace,
47
-            @Nullable final String details,
48 46
             final Date date,
49 47
             final boolean appError) {
50
-        return new ProgramError(level, message, exception, trace, details, date, eventBus, appError);
48
+        return new ProgramError(level, message, exception, date, eventBus, appError);
51 49
     }
52 50
 }

+ 18
- 18
src/com/dmdirc/logger/ProgramErrorManager.java Wyświetl plik

@@ -23,14 +23,15 @@
23 23
 package com.dmdirc.logger;
24 24
 
25 25
 import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.events.AppErrorEvent;
27 26
 import com.dmdirc.events.ErrorEvent;
28 27
 import com.dmdirc.events.FatalProgramErrorEvent;
29 28
 import com.dmdirc.events.NonFatalProgramErrorEvent;
30 29
 import com.dmdirc.events.ProgramErrorDeletedEvent;
31 30
 import com.dmdirc.events.ProgramErrorEvent;
32
-import com.dmdirc.events.UserErrorEvent;
33 31
 import com.dmdirc.util.EventUtils;
32
+import com.dmdirc.util.LogUtils;
33
+
34
+import ch.qos.logback.classic.spi.ILoggingEvent;
34 35
 
35 36
 import com.google.common.base.Throwables;
36 37
 
@@ -43,9 +44,12 @@ import java.util.HashSet;
43 44
 import java.util.Set;
44 45
 import java.util.concurrent.CopyOnWriteArraySet;
45 46
 
47
+import javax.annotation.Nullable;
46 48
 import javax.inject.Inject;
47 49
 import javax.inject.Singleton;
48 50
 
51
+import org.slf4j.Marker;
52
+
49 53
 import net.engio.mbassy.listener.Handler;
50 54
 
51 55
 /**
@@ -77,19 +81,19 @@ public class ProgramErrorManager {
77 81
         eventBus.subscribe(this);
78 82
     }
79 83
 
80
-    @Handler
81
-    void handleAppError(final AppErrorEvent event) {
82
-        handleErrorEvent(event, true);
84
+    void handle(final ILoggingEvent event) {
85
+        final ProgramError error = addError(LogUtils.getErrorLevel(event.getLevel()),
86
+                event.getFormattedMessage(), LogUtils.getThrowable(event),
87
+                isAppError(event.getMarker()));
88
+        handleErrorEvent(error);
83 89
     }
84 90
 
85
-    @Handler
86
-    void handleUserError(final UserErrorEvent event) {
87
-        handleErrorEvent(event, false);
91
+    private boolean isAppError(@Nullable final Marker marker) {
92
+        return marker != null
93
+                && (marker == LogUtils.APP_ERROR || marker == LogUtils.FATAL_APP_ERROR);
88 94
     }
89 95
 
90
-    private void handleErrorEvent(final ErrorEvent event, final boolean appError) {
91
-        final ProgramError error = addError(event.getLevel(), event.getMessage(),
92
-                event.getThrowable(), event.getDetails(), appError);
96
+    void handleErrorEvent(final ProgramError error) {
93 97
         if (error.getLevel() == ErrorLevel.FATAL) {
94 98
             eventBus.publish(new FatalProgramErrorEvent(error));
95 99
         } else {
@@ -102,10 +106,7 @@ public class ProgramErrorManager {
102 106
     void handleProgramError(final NonFatalProgramErrorEvent event) {
103 107
         if (!event.isHandled()) {
104 108
             System.err.println(event.getError().getMessage());
105
-            System.err.println(event.getError().getDetails());
106
-            if (event.getError().getThrowable() != null) {
107
-                System.err.println(Throwables.getStackTraceAsString(event.getError().getThrowable()));
108
-            }
109
+            event.getError().getThrowableAsString().ifPresent(System.err::println);
109 110
         }
110 111
     }
111 112
 
@@ -115,16 +116,15 @@ public class ProgramErrorManager {
115 116
      * @param level     The severity of the error
116 117
      * @param message   The error message
117 118
      * @param throwable The exception that caused the error, if any.
118
-     * @param details   The details of the exception, if any.
119 119
      * @param appError  Whether or not this is an application error
120 120
      *
121 121
      * @since 0.6.3m1
122 122
      */
123 123
     private ProgramError addError(final ErrorLevel level, final String message,
124
-            final Throwable throwable, final String details, final boolean appError) {
124
+            final Throwable throwable, final boolean appError) {
125 125
 
126 126
         final ProgramError error = programErrorFactory.create(level, message, throwable,
127
-                getTrace(message, throwable), details, new Date(), appError);
127
+                new Date(), appError);
128 128
         errors.add(error);
129 129
         return error;
130 130
     }

+ 3
- 11
src/com/dmdirc/logger/SentryErrorReporter.java Wyświetl plik

@@ -26,8 +26,8 @@ import com.dmdirc.interfaces.Connection;
26 26
 import com.dmdirc.util.ClientInfo;
27 27
 
28 28
 import java.util.Date;
29
+import java.util.Optional;
29 30
 
30
-import javax.annotation.Nullable;
31 31
 import javax.inject.Inject;
32 32
 import javax.inject.Singleton;
33 33
 
@@ -64,26 +64,18 @@ public class SentryErrorReporter {
64 64
      * @param level     The severity level of the error.
65 65
      * @param timestamp The timestamp that the error first occurred at.
66 66
      * @param exception The actual exception, if available.
67
-     * @param details   The details of the exception, if any.
68 67
      */
69 68
     public void sendException(
70 69
             final String message,
71 70
             final ErrorLevel level,
72 71
             final Date timestamp,
73
-            @Nullable final Throwable exception,
74
-            @Nullable final String details) {
72
+            final Optional<Throwable> exception) {
75 73
         final EventBuilder eventBuilder = newEventBuilder()
76 74
                 .withMessage(message)
77 75
                 .withLevel(getSentryLevel(level))
78 76
                 .withTimestamp(timestamp);
79 77
 
80
-        if (exception != null) {
81
-            eventBuilder.withSentryInterface(new ExceptionInterface(exception));
82
-        }
83
-
84
-        if (details != null) {
85
-            eventBuilder.withExtra("details", details);
86
-        }
78
+        exception.ifPresent(e -> eventBuilder.withSentryInterface(new ExceptionInterface(e)));
87 79
 
88 80
         send(eventBuilder.build());
89 81
     }

+ 25
- 13
src/com/dmdirc/logger/SentryLoggingErrorManager.java Wyświetl plik

@@ -30,6 +30,9 @@ import com.dmdirc.events.ProgramErrorEvent;
30 30
 import com.dmdirc.events.ProgramErrorStatusEvent;
31 31
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
32 32
 
33
+import com.google.common.base.Throwables;
34
+
35
+import java.util.Arrays;
33 36
 import java.util.Collection;
34 37
 import java.util.Optional;
35 38
 import java.util.concurrent.ExecutorService;
@@ -87,7 +90,7 @@ public class SentryLoggingErrorManager {
87 90
     void handleErrorEvent(final ProgramErrorAddedEvent error) {
88 91
         final boolean appError = error.getError().isAppError();
89 92
         if (!isValidError(error.getError().getThrowable())
90
-                || !isValidSource(error.getError().getTrace())
93
+                || !isValidSource(error.getError().getThrowable())
91 94
                 || !appError) {
92 95
             error.getError().setReportStatus(ErrorReportStatus.NOT_APPLICABLE);
93 96
             eventBus.publish(new ProgramErrorStatusEvent(error.getError()));
@@ -119,10 +122,15 @@ public class SentryLoggingErrorManager {
119 122
      *
120 123
      * @return True if the source is valid, false otherwise
121 124
      */
122
-    private boolean isValidSource(final Collection<String> trace) {
123
-        final String line = getSourceLine(trace).orElse("").trim();
124
-        return line.startsWith("at com.dmdirc")
125
-                && !line.startsWith("at com.dmdirc.addons.ui_swing.DMDircEventQueue");
125
+    private boolean isValidSource(final Optional<Throwable> throwable) {
126
+        if (throwable.isPresent()) {
127
+            final String line = getSourceLine(Arrays.asList(
128
+                    Throwables.getStackTraceAsString(throwable.get()).split("\n")))
129
+                    .orElse("").trim();
130
+            return line.startsWith("at com.dmdirc")
131
+                    && !line.startsWith("at com.dmdirc.addons.ui_swing.DMDircEventQueue");
132
+        }
133
+        return false;
126 134
     }
127 135
 
128 136
     /**
@@ -149,16 +157,20 @@ public class SentryLoggingErrorManager {
149 157
      * @since 0.6.3m1
150 158
      * @return True if the exception may be reported, false otherwise
151 159
      */
152
-    private boolean isValidError(final Throwable exception) {
153
-        Throwable target = exception;
154
-        while (target != null) {
155
-            for (Class<?> bad : BANNED_EXCEPTIONS) {
156
-                if (bad.equals(target.getClass())) {
157
-                    return false;
160
+    private boolean isValidError(final Optional<Throwable> exception) {
161
+        if (exception.isPresent()) {
162
+            @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
163
+            Throwable target = exception.get();
164
+            while (target != null) {
165
+                for (Class<?> bad : BANNED_EXCEPTIONS) {
166
+                    if (bad.equals(target.getClass())) {
167
+                        return false;
168
+                    }
158 169
                 }
170
+                target = target.getCause();
159 171
             }
160
-            target = target.getCause();
172
+            return true;
161 173
         }
162
-        return true;
174
+        return false;
163 175
     }
164 176
 }

+ 2
- 9
src/com/dmdirc/ui/FatalErrorDialog.java Wyświetl plik

@@ -32,7 +32,6 @@ import java.awt.Dialog;
32 32
 import java.awt.Dimension;
33 33
 import java.awt.event.ActionEvent;
34 34
 import java.awt.event.ActionListener;
35
-import java.util.List;
36 35
 import java.util.concurrent.CountDownLatch;
37 36
 
38 37
 import javax.swing.BorderFactory;
@@ -157,14 +156,8 @@ public final class FatalErrorDialog extends JDialog implements ActionListener {
157 156
         icon = new ImageIcon(FatalErrorDialog.class.getResource("/com/dmdirc/res/error.png"));
158 157
 
159 158
         stacktraceField.setEditable(false);
160
-
161
-        final List<String> trace = error.getTrace();
162
-        if (!trace.isEmpty()) {
163
-            for (String line : trace) {
164
-                stacktraceField.append(line + '\n');
165
-            }
166
-            stacktraceField.setCaretPosition(0);
167
-        }
159
+        error.getThrowableAsString().ifPresent(stacktraceField::append);
160
+        stacktraceField.setCaretPosition(0);
168 161
 
169 162
         scrollPane.setViewportView(stacktraceField);
170 163
 

+ 3
- 16
src/com/dmdirc/ui/core/errors/CoreErrorsDialogModel.java Wyświetl plik

@@ -33,8 +33,6 @@ import com.dmdirc.logger.ErrorReportStatus;
33 33
 import com.dmdirc.logger.ProgramError;
34 34
 import com.dmdirc.util.collections.ListenerList;
35 35
 
36
-import com.google.common.base.Throwables;
37
-
38 36
 import java.util.Collections;
39 37
 import java.util.Optional;
40 38
 import java.util.Set;
@@ -173,23 +171,12 @@ public class CoreErrorsDialogModel implements ErrorsDialogModel {
173 171
 
174 172
     private DisplayableError getDisplayableError(final ProgramError error) {
175 173
         final String details;
176
-        if (error.getDetails().isEmpty()) {
177
-            details = error.getMessage()
178
-                    + '\n' + getThrowableAsString(error.getThrowable());
174
+        if (error.getThrowableAsString().isPresent()) {
175
+            details = error.getMessage() + '\n' + error.getThrowableAsString().get();
179 176
         } else {
180
-            details = error.getMessage()
181
-                    + '\n' + error.getDetails()
182
-                    + '\n' + getThrowableAsString(error.getThrowable());
177
+            details = error.getMessage();
183 178
         }
184 179
         return new DisplayableError(error.getDate(), error.getMessage(), details,
185 180
                 error.getLevel(), error.getReportStatus(), error);
186 181
     }
187
-
188
-    private String getThrowableAsString(final Throwable throwable) {
189
-        if (throwable == null) {
190
-            return "";
191
-        } else {
192
-            return Throwables.getStackTraceAsString(throwable);
193
-        }
194
-    }
195 182
 }

+ 12
- 8
test/com/dmdirc/logger/DiskLoggingErrorManagerTest.java Wyświetl plik

@@ -24,12 +24,14 @@ package com.dmdirc.logger;
24 24
 
25 25
 import com.dmdirc.DMDircMBassador;
26 26
 import com.dmdirc.config.ConfigBinder;
27
-import com.dmdirc.events.UserErrorEvent;
27
+import com.dmdirc.events.ProgramErrorEvent;
28 28
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
29 29
 import com.dmdirc.tests.JimFsRule;
30 30
 
31 31
 import java.nio.file.Files;
32 32
 import java.nio.file.Path;
33
+import java.util.Date;
34
+import java.util.Optional;
33 35
 
34 36
 import org.junit.Before;
35 37
 import org.junit.Rule;
@@ -52,11 +54,18 @@ public class DiskLoggingErrorManagerTest {
52 54
     @Mock private DMDircMBassador eventBus;
53 55
     @Mock private AggregateConfigProvider config;
54 56
     @Mock private ConfigBinder configBinder;
57
+    @Mock private ProgramErrorEvent error;
58
+    @Mock private ProgramError programError;
55 59
 
56 60
     private DiskLoggingErrorManager instance;
57 61
 
58 62
     @Before
59 63
     public void setUp() throws Exception {
64
+        when(error.getTimestamp()).thenReturn(new Date().getTime());
65
+        when(error.getError()).thenReturn(programError);
66
+        when(programError.getThrowable()).thenReturn(Optional.of(new IllegalArgumentException()));
67
+        when(programError.getThrowableAsString()).thenReturn(Optional.of("test"));
68
+        when(programError.getLevel()).thenReturn(ErrorLevel.MEDIUM);
60 69
         when(config.getBinder()).thenReturn(configBinder);
61 70
         instance = new DiskLoggingErrorManager(jimFsRule.getFileSystem().getPath("/errors"),
62 71
                 eventBus);
@@ -78,11 +87,9 @@ public class DiskLoggingErrorManagerTest {
78 87
 
79 88
     @Test
80 89
     public void testHandleErrorEvent() throws Exception {
81
-        final UserErrorEvent error = new UserErrorEvent(ErrorLevel.MEDIUM,
82
-                new IllegalStateException(""), "", "");
83 90
         instance.initialise(config);
84 91
         instance.handleLoggingSetting(true);
85
-        final String logName = error.getTimestamp() + "-" + error.getLevel() + ".log";;
92
+        final String logName = error.getTimestamp() + "-" + error.getError().getLevel() + ".log";;
86 93
         assertFalse(Files.exists(jimFsRule.getFileSystem().getPath("/errors", logName)));
87 94
         instance.handleErrorEvent(error);
88 95
         final Path errorPath = jimFsRule.getFileSystem().getPath("/errors", logName);
@@ -92,12 +99,9 @@ public class DiskLoggingErrorManagerTest {
92 99
 
93 100
     @Test
94 101
     public void testHandleErrorEventNotLogging() throws Exception {
95
-        final UserErrorEvent error = new UserErrorEvent(ErrorLevel.MEDIUM,
96
-                new IllegalStateException(""),
97
-                "", "");
98 102
         instance.initialise(config);
99 103
         instance.handleLoggingSetting(false);
100
-        final String logName = error.getTimestamp() + "-" + error.getLevel() + ".log";;
104
+        final String logName = error.getTimestamp() + "-" + error.getError().getLevel() + ".log";;
101 105
         assertFalse(Files.exists(jimFsRule.getFileSystem().getPath("/errors", logName)));
102 106
         instance.handleErrorEvent(error);
103 107
         assertFalse(Files.exists(jimFsRule.getFileSystem().getPath("/errors", logName)));

+ 1
- 2
test/com/dmdirc/logger/ErrorReportingRunnableTest.java Wyświetl plik

@@ -48,8 +48,7 @@ public class ErrorReportingRunnableTest {
48 48
         instance.run();
49 49
         verify(programError).setReportStatus(ErrorReportStatus.SENDING);
50 50
         verify(sentryErrorReporter).sendException(programError.getMessage(), programError
51
-                .getLevel(), programError.getDate(), programError.getThrowable(),
52
-                programError.getDetails());
51
+                .getLevel(), programError.getDate(), programError.getThrowable());
53 52
         verify(programError).setReportStatus(ErrorReportStatus.FINISHED);
54 53
     }
55 54
 }

+ 14
- 34
test/com/dmdirc/logger/ProgramErrorTest.java Wyświetl plik

@@ -26,10 +26,7 @@ import com.dmdirc.DMDircMBassador;
26 26
 import com.dmdirc.events.ProgramErrorStatusEvent;
27 27
 import com.dmdirc.util.ClientInfo;
28 28
 
29
-import com.google.common.collect.Lists;
30
-
31 29
 import java.util.Date;
32
-import java.util.List;
33 30
 
34 31
 import org.junit.Test;
35 32
 import org.junit.runner.RunWith;
@@ -54,35 +51,31 @@ public class ProgramErrorTest {
54 51
 
55 52
     @Test(expected = NullPointerException.class)
56 53
     public void testConstructorNullErrorLevel() {
57
-        new ProgramError(null, "moo", null, Lists.newArrayList(), null, new Date(),
58
-                eventBus, true);
54
+        new ProgramError(null, "moo", null, new Date(),eventBus, true);
59 55
     }
60 56
 
61 57
     @Test(expected = NullPointerException.class)
62 58
     public void testConstructorNullDate() {
63
-        new ProgramError(ErrorLevel.HIGH, "moo", null, Lists.newArrayList(), null, null,
64
-                eventBus, true);
59
+        new ProgramError(ErrorLevel.HIGH, "moo", null, null, eventBus, true);
65 60
     }
66 61
 
67 62
     @Test
68 63
     public void testConstructorGood() {
69 64
         new ProgramError(ErrorLevel.HIGH, "moo", new UnsupportedOperationException(),
70
-                Lists.newArrayList(), null, new Date(), eventBus, true);
65
+                new Date(), eventBus, true);
71 66
     }
72 67
 
73 68
     @Test
74 69
     public void testGetLevel() {
75 70
         final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo",
76
-                new UnsupportedOperationException(), Lists.newArrayList(), null, new Date(),
77
-                eventBus, true);
71
+                new UnsupportedOperationException(), new Date(), eventBus, true);
78 72
         assertEquals(ErrorLevel.HIGH, pe.getLevel());
79 73
     }
80 74
 
81 75
     @Test
82 76
     public void testGetMessage() {
83 77
         final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo",
84
-                new UnsupportedOperationException(), Lists.newArrayList(), null, new Date(),
85
-                eventBus, true);
78
+                new UnsupportedOperationException(), new Date(), eventBus, true);
86 79
         assertEquals("moo", pe.getMessage());
87 80
     }
88 81
 
@@ -90,24 +83,21 @@ public class ProgramErrorTest {
90 83
     public void testGetDate() {
91 84
         final Date date = new Date();
92 85
         final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo",
93
-                new UnsupportedOperationException(), Lists.newArrayList(), null, date,
94
-                eventBus, true);
86
+                new UnsupportedOperationException(), date, eventBus, true);
95 87
         assertEquals(date, pe.getDate());
96 88
     }
97 89
 
98 90
     @Test
99 91
     public void testIsAppError() {
100 92
         final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo",
101
-                new UnsupportedOperationException(), Lists.newArrayList(), null, new Date(),
102
-                eventBus, true);
93
+                new UnsupportedOperationException(), new Date(), eventBus, true);
103 94
         assertTrue(pe.isAppError());
104 95
     }
105 96
 
106 97
     @Test
107 98
     public void testReportStatus() {
108 99
         final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo",
109
-                new UnsupportedOperationException(), Lists.newArrayList(), null, new Date(),
110
-                eventBus, true);
100
+                new UnsupportedOperationException(), new Date(), eventBus, true);
111 101
         assertEquals(ErrorReportStatus.WAITING, pe.getReportStatus());
112 102
         pe.setReportStatus(null);
113 103
         assertEquals(ErrorReportStatus.WAITING, pe.getReportStatus());
@@ -124,33 +114,23 @@ public class ProgramErrorTest {
124 114
     @Test
125 115
     public void testToString() {
126 116
         final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo",
127
-                new UnsupportedOperationException(), Lists.newArrayList(), null, new Date(),
128
-                eventBus, true);
117
+                new UnsupportedOperationException(), new Date(), eventBus, true);
129 118
         assertTrue(pe.toString().contains("moo"));
130 119
     }
131 120
 
132
-    @Test
133
-    public void testGetTrace() {
134
-        final List<String> trace = Lists.newArrayList("test", "test1", "test2");
135
-        final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo",
136
-                new UnsupportedOperationException(), trace, null, new Date(),
137
-                eventBus, true);
138
-        assertEquals(trace, pe.getTrace());
139
-    }
140
-
141 121
     @Test
142 122
     public void testEquals() {
143 123
         final Exception ex = new UnsupportedOperationException();
144 124
         final ProgramError pe1 = new ProgramError(ErrorLevel.LOW, "moo",
145
-                ex, Lists.newArrayList(), null, new Date(), eventBus, true);
125
+                ex, new Date(), eventBus, true);
146 126
         final ProgramError pe2 = new ProgramError(ErrorLevel.LOW, "moo",
147
-                ex, Lists.newArrayList(), null, new Date(), eventBus, true);
127
+                ex, new Date(), eventBus, true);
148 128
         final ProgramError pe3 = new ProgramError(ErrorLevel.MEDIUM, "moo",
149
-                ex, Lists.newArrayList(), null, new Date(), eventBus, true);
129
+                ex, new Date(), eventBus, true);
150 130
         final ProgramError pe4 = new ProgramError(ErrorLevel.LOW, "bar",
151
-                ex, Lists.newArrayList(), null, new Date(), eventBus, true);
131
+                ex, new Date(), eventBus, true);
152 132
         final ProgramError pe5 = new ProgramError(ErrorLevel.LOW, "moo",
153
-                null, Lists.newArrayList(), "Hello", new Date(), eventBus, true);
133
+                null, new Date(), eventBus, true);
154 134
 
155 135
         assertFalse(pe1.equals(null)); // NOPMD
156 136
         assertFalse(pe1.equals("moo"));

+ 12
- 16
test/com/dmdirc/logger/SentryErrorReporterTest.java Wyświetl plik

@@ -25,6 +25,7 @@ package com.dmdirc.logger;
25 25
 import com.dmdirc.util.ClientInfo;
26 26
 
27 27
 import java.util.Date;
28
+import java.util.Optional;
28 29
 
29 30
 import org.junit.Before;
30 31
 import org.junit.BeforeClass;
@@ -57,6 +58,7 @@ public class SentryErrorReporterTest {
57 58
     @Mock private Raven raven;
58 59
     @Mock private ClientInfo clientInfo;
59 60
     @Captor private ArgumentCaptor<Event> eventCaptor;
61
+    private Optional<Throwable> throwable;
60 62
     private SentryErrorReporter sentryErrorReporter;
61 63
 
62 64
     @BeforeClass
@@ -69,12 +71,13 @@ public class SentryErrorReporterTest {
69 71
     @Before
70 72
     public void setUp() {
71 73
         when(ravenFactory.createRavenInstance(Matchers.<Dsn>anyObject())).thenReturn(raven);
74
+        throwable = Optional.of(new IllegalArgumentException());
72 75
         sentryErrorReporter = new SentryErrorReporter(clientInfo);
73 76
     }
74 77
 
75 78
     @Test
76 79
     public void testSendsMessage() {
77
-        sentryErrorReporter.sendException("message 123", ErrorLevel.MEDIUM, new Date(), null, null);
80
+        sentryErrorReporter.sendException("message 123", ErrorLevel.MEDIUM, new Date(), throwable);
78 81
         verify(raven).sendEvent(eventCaptor.capture());
79 82
         assertEquals("message 123", eventCaptor.getValue().getMessage());
80 83
     }
@@ -82,58 +85,51 @@ public class SentryErrorReporterTest {
82 85
     @Test
83 86
     public void testSendsTimestamp() {
84 87
         final Date date = new Date(561859200000l);
85
-        sentryErrorReporter.sendException("message 123", ErrorLevel.MEDIUM, date, null, null);
88
+        sentryErrorReporter.sendException("message 123", ErrorLevel.MEDIUM, date, throwable);
86 89
         verify(raven).sendEvent(eventCaptor.capture());
87 90
         assertEquals(date, eventCaptor.getValue().getTimestamp());
88 91
     }
89 92
 
90 93
     @Test
91 94
     public void testSendsLowLevelAsInfo() {
92
-        sentryErrorReporter.sendException("message 123", ErrorLevel.LOW, new Date(), null, null);
95
+        sentryErrorReporter.sendException("message 123", ErrorLevel.LOW, new Date(), throwable);
93 96
         verify(raven).sendEvent(eventCaptor.capture());
94 97
         assertEquals(Event.Level.INFO, eventCaptor.getValue().getLevel());
95 98
     }
96 99
 
97 100
     @Test
98 101
     public void testSendsMediumLevelAsWarning() {
99
-        sentryErrorReporter.sendException("message 123", ErrorLevel.MEDIUM, new Date(), null, null);
102
+        sentryErrorReporter.sendException("message 123", ErrorLevel.MEDIUM, new Date(), throwable);
100 103
         verify(raven).sendEvent(eventCaptor.capture());
101 104
         assertEquals(Event.Level.WARNING, eventCaptor.getValue().getLevel());
102 105
     }
103 106
 
104 107
     @Test
105 108
     public void testSendsHighLevelAsError() {
106
-        sentryErrorReporter.sendException("message 123", ErrorLevel.HIGH, new Date(), null, null);
109
+        sentryErrorReporter.sendException("message 123", ErrorLevel.HIGH, new Date(), throwable);
107 110
         verify(raven).sendEvent(eventCaptor.capture());
108 111
         assertEquals(Event.Level.ERROR, eventCaptor.getValue().getLevel());
109 112
     }
110 113
 
111 114
     @Test
112 115
     public void testSendsFatalLevelAsFatal() {
113
-        sentryErrorReporter.sendException("message 123", ErrorLevel.FATAL, new Date(), null, null);
116
+        sentryErrorReporter.sendException("message 123", ErrorLevel.FATAL, new Date(), throwable);
114 117
         verify(raven).sendEvent(eventCaptor.capture());
115 118
         assertEquals(Event.Level.FATAL, eventCaptor.getValue().getLevel());
116 119
     }
117 120
 
118 121
     @Test
119 122
     public void testSendsUnknownLevelAsInfo() {
120
-        sentryErrorReporter.sendException("message 123", ErrorLevel.UNKNOWN, new Date(), null, null);
123
+        sentryErrorReporter.sendException("message 123", ErrorLevel.UNKNOWN, new Date(), throwable);
121 124
         verify(raven).sendEvent(eventCaptor.capture());
122 125
         assertEquals(Event.Level.INFO, eventCaptor.getValue().getLevel());
123 126
     }
124 127
 
125
-    @Test
126
-    public void testAddsDetailsAsExtra() {
127
-        sentryErrorReporter.sendException("message 123", ErrorLevel.UNKNOWN, new Date(), null,
128
-                "details 456");
129
-        verify(raven).sendEvent(eventCaptor.capture());
130
-        assertEquals("details 456", eventCaptor.getValue().getExtra().get("details"));
131
-    }
132
-
133 128
     @Test
134 129
     public void testAddsExceptionInterface() {
135 130
         final Exception exception = new IndexOutOfBoundsException("Message blah");
136
-        sentryErrorReporter.sendException("message 123", ErrorLevel.UNKNOWN, new Date(), exception, null);
131
+        sentryErrorReporter.sendException("message 123", ErrorLevel.UNKNOWN, new Date(),
132
+                Optional.of(exception));
137 133
         verify(raven).sendEvent(eventCaptor.capture());
138 134
         final SentryInterface iface = eventCaptor.getValue().getSentryInterfaces()
139 135
                 .get(ExceptionInterface.EXCEPTION_INTERFACE);

+ 11
- 36
test/com/dmdirc/logger/SentryLoggingErrorManagerTest.java Wyświetl plik

@@ -27,10 +27,10 @@ import com.dmdirc.config.ConfigBinder;
27 27
 import com.dmdirc.events.ProgramErrorAddedEvent;
28 28
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
29 29
 
30
-import com.google.common.collect.Lists;
31 30
 import com.google.common.util.concurrent.MoreExecutors;
32 31
 
33 32
 import java.util.Date;
33
+import java.util.Optional;
34 34
 
35 35
 import org.junit.Before;
36 36
 import org.junit.Test;
@@ -62,10 +62,10 @@ public class SentryLoggingErrorManagerTest {
62 62
     public void setUp() throws Exception {
63 63
         when(appErrorEvent.getError()).thenReturn(appError);
64 64
         when(appError.isAppError()).thenReturn(true);
65
-        when(appError.getThrowable()).thenReturn(new IllegalStateException());
66
-        when(appError.getTrace()).thenReturn(Lists.newArrayList("at com.dmdirc.Main"));
65
+        when(appError.getThrowable()).thenReturn(Optional.of(new IllegalStateException()));
67 66
         when(userErrorEvent.getError()).thenReturn(userError);
68 67
         when(userError.isAppError()).thenReturn(false);
68
+        when(userError.getThrowable()).thenReturn(Optional.of(new IllegalStateException()));
69 69
         when(config.getBinder()).thenReturn(configBinder);
70 70
         instance = new SentryLoggingErrorManager(eventBus, sentryErrorReporter,
71 71
                 MoreExecutors.newDirectExecutorService());
@@ -78,48 +78,23 @@ public class SentryLoggingErrorManagerTest {
78 78
     public void testHandleErrorEvent() throws Exception {
79 79
         instance.handleErrorEvent(appErrorEvent);
80 80
         verify(sentryErrorReporter).sendException(anyString(), any(ErrorLevel.class),
81
-                any(Date.class), any(Throwable.class), anyString());
82
-    }
83
-
84
-    @Test
85
-    public void testHandleErrorEvent_DMDircEventQueue() throws Exception {
86
-        when(appError.getTrace()).thenReturn(Lists.newArrayList("at com.dmdirc.addons.ui_swing" +
87
-                ".DMDircEventQueue", "java.somethingelse"));
88
-        instance.handleErrorEvent(appErrorEvent);
89
-        verify(sentryErrorReporter, never()).sendException(anyString(), any(ErrorLevel.class),
90
-                any(Date.class), any(Throwable.class), anyString());
91
-    }
92
-
93
-    @Test
94
-    public void testHandleErrorEvent_No_com_dmdirc() throws Exception {
95
-        when(appError.getTrace()).thenReturn(Lists.newArrayList("java.util", "java.somethingelse"));
96
-        instance.handleErrorEvent(appErrorEvent);
97
-        verify(sentryErrorReporter, never()).sendException(anyString(), any(ErrorLevel.class),
98
-                any(Date.class), any(Throwable.class), anyString());
81
+                any(Date.class), any(Optional.class));
99 82
     }
100 83
 
101 84
     @Test
102 85
     public void testHandledErrorEvent_UserError() throws Exception {
103 86
         instance.handleErrorEvent(userErrorEvent);
104 87
         verify(sentryErrorReporter, never()).sendException(anyString(), any(ErrorLevel.class),
105
-                any(Date.class), any(Throwable.class), anyString());
106
-    }
107
-
108
-    @Test
109
-    public void testHandledErrorEvent_EmptyTrace() throws Exception {
110
-        when(appError.getTrace()).thenReturn(Lists.newArrayList());
111
-        instance.handleErrorEvent(appErrorEvent);
112
-        verify(sentryErrorReporter, never()).sendException(anyString(), any(ErrorLevel.class),
113
-                any(Date.class), any(Throwable.class), anyString());
88
+                any(Date.class), any(Optional.class));
114 89
     }
115 90
 
116 91
     @Test
117 92
     public void testHandledErrorEvent_BannedException() throws Exception {
118 93
         final Throwable throwable = new OutOfMemoryError();
119
-        when(appError.getThrowable()).thenReturn(throwable);
94
+        when(appError.getThrowable()).thenReturn(Optional.of(throwable));
120 95
         instance.handleErrorEvent(appErrorEvent);
121 96
         verify(sentryErrorReporter, never()).sendException(anyString(), any(ErrorLevel.class),
122
-                any(Date.class), eq(throwable), anyString());
97
+                any(Date.class), eq(Optional.of(throwable)));
123 98
     }
124 99
 
125 100
     @Test
@@ -128,7 +103,7 @@ public class SentryLoggingErrorManagerTest {
128 103
         instance.handleNoErrorReporting(false);
129 104
         instance.handleErrorEvent(appErrorEvent);
130 105
         verify(sentryErrorReporter, never()).sendException(anyString(), any(ErrorLevel.class),
131
-                any(Date.class), any(Throwable.class), anyString());
106
+                any(Date.class), any(Optional.class));
132 107
     }
133 108
 
134 109
     @Test
@@ -137,7 +112,7 @@ public class SentryLoggingErrorManagerTest {
137 112
         instance.handleNoErrorReporting(true);
138 113
         instance.handleErrorEvent(appErrorEvent);
139 114
         verify(sentryErrorReporter, never()).sendException(anyString(), any(ErrorLevel.class),
140
-                any(Date.class), any(Throwable.class), anyString());
115
+                any(Date.class), any(Optional.class));
141 116
     }
142 117
 
143 118
     @Test
@@ -146,7 +121,7 @@ public class SentryLoggingErrorManagerTest {
146 121
         instance.handleNoErrorReporting(false);
147 122
         instance.handleErrorEvent(appErrorEvent);
148 123
         verify(sentryErrorReporter).sendException(anyString(), any(ErrorLevel.class),
149
-                any(Date.class), any(Throwable.class), anyString());
124
+                any(Date.class), any(Optional.class));
150 125
     }
151 126
 
152 127
     @Test
@@ -155,6 +130,6 @@ public class SentryLoggingErrorManagerTest {
155 130
         instance.handleNoErrorReporting(true);
156 131
         instance.handleErrorEvent(appErrorEvent);
157 132
         verify(sentryErrorReporter, never()).sendException(anyString(), any(ErrorLevel.class),
158
-                any(Date.class), any(Throwable.class), anyString());
133
+                any(Date.class), any(Optional.class));
159 134
     }
160 135
 }

Ładowanie…
Anuluj
Zapisz