Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy up some error handling. #466

Merged
merged 2 commits into from
Jan 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 13 additions & 30 deletions src/com/dmdirc/logger/ProgramErrorManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
package com.dmdirc.logger;

import com.dmdirc.DMDircMBassador;
import com.dmdirc.events.AppErrorEvent;
import com.dmdirc.events.ErrorEvent;
import com.dmdirc.events.FatalProgramErrorEvent;
import com.dmdirc.events.NonFatalProgramErrorEvent;
import com.dmdirc.events.ProgramErrorDeletedEvent;
import com.dmdirc.events.ProgramErrorEvent;
import com.dmdirc.events.UserErrorEvent;
import com.dmdirc.util.EventUtils;

import com.google.common.base.Throwables;
Expand All @@ -52,12 +54,6 @@
@Singleton
public class ProgramErrorManager {

/** A list of exceptions which we don't consider bugs and thus don't report. */
private static final Class<?>[] BANNED_EXCEPTIONS = new Class<?>[]{
NoSuchMethodError.class, NoClassDefFoundError.class,
UnsatisfiedLinkError.class, AbstractMethodError.class,
IllegalAccessError.class, OutOfMemoryError.class,
NoSuchFieldError.class,};
/** The event bus to listen for errors on. */
private final DMDircMBassador eventBus;
/** The current list of errors. */
Expand All @@ -81,9 +77,18 @@ public void initialise() {
}

@Handler
void handleErrorEvent(final ErrorEvent event) {
void handleAppError(final AppErrorEvent event) {
handleErrorEvent(event, true);
}

@Handler
void handleUserError(final UserErrorEvent event) {
handleErrorEvent(event, false);
}

private void handleErrorEvent(final ErrorEvent event, final boolean appError) {
final ProgramError error = addError(event.getLevel(), event.getMessage(),
event.getThrowable(), event.getDetails(), isValidError(event.getThrowable()));
event.getThrowable(), event.getDetails(), appError);
if (error.getLevel() == ErrorLevel.FATAL) {
eventBus.publish(new FatalProgramErrorEvent(error));
} else {
Expand Down Expand Up @@ -160,26 +165,4 @@ public void deleteAll() {
public Set<ProgramError> getErrors() {
return Collections.unmodifiableSet(errors);
}

/**
* Determines whether or not the specified exception is one that we are willing to report.
*
* @param exception The exception to test
*
* @since 0.6.3m1
* @return True if the exception may be reported, false otherwise
*/
private boolean isValidError(final Throwable exception) {
// TODO: Dedupe this from here and SentryLoggingErrorManager
Throwable target = exception;
while (target != null) {
for (Class<?> bad : BANNED_EXCEPTIONS) {
if (bad.equals(target.getClass())) {
return false;
}
}
target = target.getCause();
}
return true;
}
}
1 change: 0 additions & 1 deletion src/com/dmdirc/logger/SentryLoggingErrorManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ private Optional<String> getSourceLine(final Collection<String> trace) {
* @return True if the exception may be reported, false otherwise
*/
private boolean isValidError(final Throwable exception) {
// TODO: Dedupe this from here and ProgramErrorManager
Throwable target = exception;
while (target != null) {
for (Class<?> bad : BANNED_EXCEPTIONS) {
Expand Down
5 changes: 4 additions & 1 deletion src/com/dmdirc/ui/core/errors/CoreErrorsDialogModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.dmdirc.interfaces.ui.ErrorsDialogModel;
import com.dmdirc.interfaces.ui.ErrorsDialogModelListener;
import com.dmdirc.logger.ErrorManager;
import com.dmdirc.logger.ErrorReportStatus;
import com.dmdirc.logger.ProgramError;
import com.dmdirc.util.collections.ListenerList;

Expand Down Expand Up @@ -122,7 +123,9 @@ public boolean isDeleteAllAllowed() {

@Override
public boolean isSendAllowed() {
return selectedError.isPresent();
final ErrorReportStatus status = selectedError.map(DisplayableError::getReportStatus)
.orElse(ErrorReportStatus.NOT_APPLICABLE);
return status == ErrorReportStatus.WAITING || status == ErrorReportStatus.ERROR;
}

@Override
Expand Down