diff --git a/src/com/dmdirc/logger/ErrorManager.java b/src/com/dmdirc/logger/ErrorManager.java index dee51efd7..55dc4c6e6 100644 --- a/src/com/dmdirc/logger/ErrorManager.java +++ b/src/com/dmdirc/logger/ErrorManager.java @@ -179,7 +179,7 @@ public void handleUserErrorEvent(final UserErrorEvent userError) { protected ProgramError addError(final ErrorLevel level, final String message, final Throwable exception, final String details, final boolean appError, final boolean canReport) { - return addError(getError(level, message, exception, details), appError, canReport); + return addError(getError(level, message, exception, details, appError), appError, canReport); } protected ProgramError addError( @@ -256,9 +256,9 @@ protected void addError(final ProgramError error) { * @return A corresponding ProgramError */ protected ProgramError getError(final ErrorLevel level, final String message, - final Throwable exception, final String details) { + final Throwable exception, final String details, final boolean appError) { return new ProgramError(level, message, exception, getTrace(message, exception), details, - new Date(), this, eventBus); + new Date(), this, eventBus, appError); } /** diff --git a/src/com/dmdirc/logger/ProgramError.java b/src/com/dmdirc/logger/ProgramError.java index b4ce7bd3d..f0e9c6601 100644 --- a/src/com/dmdirc/logger/ProgramError.java +++ b/src/com/dmdirc/logger/ProgramError.java @@ -62,6 +62,8 @@ public class ProgramError implements Serializable { private final ErrorManager errorManager; /** The eventbus to post status changes to. */ private final DMDircMBassador eventBus; + /** Is this an application error? */ + private final boolean appError; /** Error report Status. */ private ErrorReportStatus reportStatus; /** Has the error been output. */ @@ -84,7 +86,8 @@ public ProgramError(final ErrorLevel level, final String message, @Nullable final String details, final Date date, final ErrorManager errorManager, - final DMDircMBassador eventBus) { + final DMDircMBassador eventBus, + final boolean appError) { checkNotNull(level); checkNotNull(message); checkNotNull(date); @@ -99,6 +102,7 @@ public ProgramError(final ErrorLevel level, final String message, this.reportStatus = ErrorReportStatus.WAITING; this.errorManager = errorManager; this.eventBus = eventBus; + this.appError = appError; } /** @@ -183,6 +187,15 @@ public boolean isHandled() { return handled; } + /** + * Is this an application error? + * + * @return true iif this is an application error + */ + public boolean isAppError() { + return appError; + } + @Override public String toString() { return MoreObjects.toStringHelper(this) diff --git a/test/com/dmdirc/logger/ProgramErrorTest.java b/test/com/dmdirc/logger/ProgramErrorTest.java index 50e9b232f..3712fa346 100644 --- a/test/com/dmdirc/logger/ProgramErrorTest.java +++ b/test/com/dmdirc/logger/ProgramErrorTest.java @@ -55,38 +55,38 @@ public class ProgramErrorTest { @Test(expected = NullPointerException.class) public void testConstructorNullErrorLevel() { new ProgramError(null, "moo", null, Lists.newArrayList(), null, new Date(), errorManager, - eventBus); + eventBus, true); } @Test(expected = NullPointerException.class) public void testConstructorNullMessage() { new ProgramError(ErrorLevel.HIGH, null, null, Lists.newArrayList(), null, new Date(), - errorManager, eventBus); + errorManager, eventBus, true); } @Test(expected = IllegalArgumentException.class) public void testConstructorEmptyMessage() { new ProgramError(ErrorLevel.HIGH, "", null, Lists.newArrayList(), null, new Date(), - errorManager, eventBus); + errorManager, eventBus, true); } @Test(expected = NullPointerException.class) public void testConstructorNullDate() { new ProgramError(ErrorLevel.HIGH, "moo", null, Lists.newArrayList(), null, null, - errorManager, eventBus); + errorManager, eventBus, true); } @Test public void testConstructorGood() { new ProgramError(ErrorLevel.HIGH, "moo", new UnsupportedOperationException(), - Lists.newArrayList(), null, new Date(), errorManager, eventBus); + Lists.newArrayList(), null, new Date(), errorManager, eventBus, true); } @Test public void testGetLevel() { final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo", new UnsupportedOperationException(), Lists.newArrayList(), null, new Date(), - errorManager, eventBus); + errorManager, eventBus, true); assertEquals(ErrorLevel.HIGH, pe.getLevel()); } @@ -94,7 +94,7 @@ public void testGetLevel() { public void testGetMessage() { final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo", new UnsupportedOperationException(), Lists.newArrayList(), null, new Date(), - errorManager, eventBus); + errorManager, eventBus, true); assertEquals("moo", pe.getMessage()); } @@ -103,15 +103,23 @@ public void testGetDate() { final Date date = new Date(); final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo", new UnsupportedOperationException(), Lists.newArrayList(), null, date, - errorManager, eventBus); + errorManager, eventBus, true); assertEquals(date, pe.getDate()); } + @Test + public void testIsAppError() { + final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo", + new UnsupportedOperationException(), Lists.newArrayList(), null, new Date(), + errorManager, eventBus, true); + assertTrue(pe.isAppError()); + } + @Test public void testReportStatus() { final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo", new UnsupportedOperationException(), Lists.newArrayList(), null, new Date(), - errorManager, eventBus); + errorManager, eventBus, true); assertEquals(ErrorReportStatus.WAITING, pe.getReportStatus()); pe.setReportStatus(null); assertEquals(ErrorReportStatus.WAITING, pe.getReportStatus()); @@ -129,7 +137,7 @@ public void testReportStatus() { public void testToString() { final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo", new UnsupportedOperationException(), Lists.newArrayList(), null, new Date(), - errorManager, eventBus); + errorManager, eventBus, true); assertTrue(pe.toString().contains("moo")); } @@ -138,7 +146,7 @@ public void testGetTrace() { final List trace = Lists.newArrayList("test", "test1", "test2"); final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo", new UnsupportedOperationException(), trace, null, new Date(), errorManager, - eventBus); + eventBus, true); assertEquals(trace, pe.getTrace()); } @@ -146,15 +154,15 @@ public void testGetTrace() { public void testEquals() { final Exception ex = new UnsupportedOperationException(); final ProgramError pe1 = new ProgramError(ErrorLevel.LOW, "moo", - ex, Lists.newArrayList(), null, new Date(), errorManager, eventBus); + ex, Lists.newArrayList(), null, new Date(), errorManager, eventBus, true); final ProgramError pe2 = new ProgramError(ErrorLevel.LOW, "moo", - ex, Lists.newArrayList(), null, new Date(), errorManager, eventBus); + ex, Lists.newArrayList(), null, new Date(), errorManager, eventBus, true); final ProgramError pe3 = new ProgramError(ErrorLevel.MEDIUM, "moo", - ex, Lists.newArrayList(), null, new Date(), errorManager, eventBus); + ex, Lists.newArrayList(), null, new Date(), errorManager, eventBus, true); final ProgramError pe4 = new ProgramError(ErrorLevel.LOW, "bar", - ex, Lists.newArrayList(), null, new Date(), errorManager, eventBus); + ex, Lists.newArrayList(), null, new Date(), errorManager, eventBus, true); final ProgramError pe5 = new ProgramError(ErrorLevel.LOW, "moo", - null, Lists.newArrayList(), "Hello", new Date(), errorManager, eventBus); + null, Lists.newArrayList(), "Hello", new Date(), errorManager, eventBus, true); assertFalse(pe1.equals(null)); // NOPMD assertFalse(pe1.equals("moo"));