Skip to content

Commit

Permalink
Change a couple of event bus error reportings.
Browse files Browse the repository at this point in the history
  • Loading branch information
csmith committed Feb 1, 2015
1 parent 1777aad commit 1e3b0b5
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 120 deletions.
2 changes: 1 addition & 1 deletion src/com/dmdirc/Main.java
Expand Up @@ -175,7 +175,7 @@ public static void main(final String... args) {
* Initialises the client.
*/
public void init() {
Thread.setDefaultUncaughtExceptionHandler(new DMDircExceptionHandler(eventBus));
Thread.setDefaultUncaughtExceptionHandler(new DMDircExceptionHandler());
setupLogback();
migrators.stream().filter(Migrator::needsMigration).forEach(Migrator::migrate);
commands.forEach(c -> commandManager.registerCommand(c.getCommand(), c.getInfo()));
Expand Down
22 changes: 8 additions & 14 deletions src/com/dmdirc/logger/DMDircExceptionHandler.java
Expand Up @@ -22,28 +22,22 @@

package com.dmdirc.logger;

import com.dmdirc.DMDircMBassador;
import com.dmdirc.events.AppErrorEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.dmdirc.util.LogUtils.APP_ERROR;
import static com.dmdirc.util.LogUtils.FATAL_APP_ERROR;

/**
* Passes uncaught exceptions to the logger.
*/
public final class DMDircExceptionHandler implements
Thread.UncaughtExceptionHandler {

private final DMDircMBassador eventBus;
public final class DMDircExceptionHandler implements Thread.UncaughtExceptionHandler {

public DMDircExceptionHandler(final DMDircMBassador eventBus) {
this.eventBus = eventBus;
}
private static final Logger LOG = LoggerFactory.getLogger(DMDircExceptionHandler.class);

@Override
public void uncaughtException(final Thread t, final Throwable e) {
if (e instanceof Error) {
eventBus.publish(new AppErrorEvent(ErrorLevel.FATAL, e, e.toString(), ""));
} else {
eventBus.publish(new AppErrorEvent(ErrorLevel.HIGH, e, e.toString(), ""));
}
LOG.error(e instanceof Error ? FATAL_APP_ERROR : APP_ERROR, "Uncaught exception", e);
}

}
19 changes: 10 additions & 9 deletions src/com/dmdirc/logger/ModeAliasReporter.java
Expand Up @@ -22,35 +22,37 @@

package com.dmdirc.logger;

import com.dmdirc.DMDircMBassador;
import com.dmdirc.MissingModeAliasException;
import com.dmdirc.events.AppErrorEvent;
import com.dmdirc.events.ServerConnectedEvent;
import com.dmdirc.interfaces.config.AggregateConfigProvider;
import com.dmdirc.parser.interfaces.Parser;

import javax.inject.Inject;
import javax.inject.Singleton;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.engio.mbassy.listener.Handler;
import net.engio.mbassy.listener.Listener;
import net.engio.mbassy.listener.References;

import static com.dmdirc.util.LogUtils.APP_ERROR;

/**
* Watches for newly connected servers and raises errors about their mode aliases.
*/
@Singleton
@Listener(references = References.Strong)
public class ModeAliasReporter {

private static final Logger LOG = LoggerFactory.getLogger(ModeAliasReporter.class);

/** The name of the server domain. */
private static final String DOMAIN_SERVER = "server";

private final DMDircMBassador eventBus;

@Inject
public ModeAliasReporter(final DMDircMBassador eventBus) {
this.eventBus = eventBus;
public ModeAliasReporter() {
}

@Handler
Expand Down Expand Up @@ -99,13 +101,12 @@ public void handleServerConnected(final ServerConnectedEvent event) {
}


eventBus.publish(new AppErrorEvent(ErrorLevel.LOW,
new MissingModeAliasException(
LOG.info(APP_ERROR, "Missing mode aliases", new MissingModeAliasException(
event.getConnection().getNetwork(),
parser,
configManager.getOption("identity", "modealiasversion"),
missing.toString()),
missing + " [" + parser.getServerSoftwareType() + ']', ""));
missing + " [" + parser.getServerSoftwareType() + ']', "");
}
}
}
44 changes: 21 additions & 23 deletions src/com/dmdirc/plugins/PluginInfo.java
Expand Up @@ -25,13 +25,10 @@
import com.dmdirc.DMDircMBassador;
import com.dmdirc.config.ConfigFileBackedConfigProvider;
import com.dmdirc.config.InvalidIdentityFileException;
import com.dmdirc.events.AppErrorEvent;
import com.dmdirc.events.PluginLoadedEvent;
import com.dmdirc.events.PluginUnloadedEvent;
import com.dmdirc.events.UserErrorEvent;
import com.dmdirc.interfaces.config.ConfigProvider;
import com.dmdirc.interfaces.config.IdentityController;
import com.dmdirc.logger.ErrorLevel;
import com.dmdirc.util.validators.ValidationResponse;

import java.io.IOException;
Expand All @@ -57,6 +54,9 @@

import dagger.ObjectGraph;

import static com.dmdirc.util.LogUtils.APP_ERROR;
import static com.dmdirc.util.LogUtils.USER_ERROR;

/**
* Stores plugin metadata and handles loading of plugin resources.
*/
Expand Down Expand Up @@ -253,8 +253,8 @@ private void loadIdentities() {
directoryStream.forEach(this::loadIdentity);
}
} catch (final IOException ioe) {
eventBus.publish(new UserErrorEvent(ErrorLevel.MEDIUM, ioe,
"Error finding identities in plugin '" + metaData.getName() + '\'', ""));
LOG.warn(USER_ERROR, "Error finding identities in plugin '{}'", metaData.getName(),
ioe);
}
}

Expand All @@ -271,14 +271,12 @@ private void loadIdentity(final Path path) {
identityController.addConfigProvider(configProvider);
configProviders.add(configProvider);
}
} catch (final InvalidIdentityFileException ex) {
eventBus.publish(new UserErrorEvent(ErrorLevel.MEDIUM, ex,
"Error with identity file '" + path.getFileName() + "' in plugin '" +
metaData.getName() + '\'', ""));
} catch (InvalidIdentityFileException ex) {
LOG.warn(USER_ERROR, "Error with identity file '{}' in plugin '{}'",
path.getFileName(), metaData.getName(), ex);
} catch (IOException ex) {
eventBus.publish(new UserErrorEvent(ErrorLevel.MEDIUM, ex,
"Unable to load identity file '" + path.getFileName() + "' in plugin '" +
metaData.getName() + '\'', ""));
LOG.warn(USER_ERROR, "Unable to load identity file '{}' in plugin '{}'",
path.getFileName(), metaData.getName(), ex);
}
}

Expand Down Expand Up @@ -330,10 +328,10 @@ private void updateProvides() {
* files.
*/
public void pluginUpdated() throws PluginException {
updateClassList();
updateMetaData();
updateProvides();
getDefaults();
updateClassList();
updateMetaData();
updateProvides();
getDefaults();
}

/**
Expand Down Expand Up @@ -597,23 +595,23 @@ private void loadMainClass() {
lastError = "Class not found ('" + filename + ':' + classname + ':'
+ classname.equals(metaData.getMainClass()) + "') - "
+ cnfe.getMessage();
eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, cnfe, lastError, ""));
LOG.info(USER_ERROR, lastError, cnfe);
} catch (NoClassDefFoundError ncdf) {
lastError = "Unable to instantiate plugin ('" + filename + ':'
+ classname + ':'
+ classname.equals(metaData.getMainClass())
+ "') - Unable to find class: " + ncdf.getMessage();
eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ncdf, lastError, ""));
LOG.info(USER_ERROR, lastError, ncdf);
} catch (VerifyError ve) {
lastError = "Unable to instantiate plugin ('" + filename + ':'
+ classname + ':'
+ classname.equals(metaData.getMainClass())
+ "') - Incompatible: " + ve.getMessage();
eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ve, lastError, ""));
LOG.info(USER_ERROR, lastError, ve);
} catch (IllegalArgumentException | ReflectiveOperationException ex) {
lastError = "Unable to instantiate class for plugin " + metaData.getName()
+ ": " + classname;
eventBus.publishAsync(new AppErrorEvent(ErrorLevel.LOW, ex, lastError, ""));
LOG.info(APP_ERROR, lastError, ex);
}
}

Expand All @@ -626,7 +624,7 @@ private void createMainClass(final Class<?> clazz) throws InstantiationException
lastError = "Prerequisites for plugin not met. ('"
+ filename + ':' + metaData.getMainClass()
+ "' -> '" + prerequisites.getFailureReason() + "') ";
eventBus.publish(new UserErrorEvent(ErrorLevel.LOW, null, lastError, ""));
LOG.info(USER_ERROR, lastError);
} else {
initialisePlugin((Plugin) temp);
}
Expand All @@ -640,7 +638,7 @@ private void initialisePlugin(final Plugin temp) {
plugin.onLoad();
} catch (LinkageError | Exception e) {
lastError = "Error in onLoad for " + metaData.getName() + ':' + e.getMessage();
eventBus.publishAsync(new AppErrorEvent(ErrorLevel.MEDIUM, e, lastError, ""));
LOG.warn(APP_ERROR, lastError, e);
unloadPlugin();
}
}
Expand Down Expand Up @@ -698,7 +696,7 @@ private void unloadPlugin(final boolean parentUnloading) {
} catch (Exception | LinkageError e) {
lastError = "Error in onUnload for " + metaData.getName()
+ ':' + e + " - " + e.getMessage();
eventBus.publishAsync(new AppErrorEvent(ErrorLevel.MEDIUM, e, lastError, ""));
LOG.warn(APP_ERROR, lastError, e);
}

//TODO plugin unloading shouldn't be done from here, event bus shouldn't be here.
Expand Down
73 changes: 0 additions & 73 deletions test/com/dmdirc/logger/DMDircExceptionHandlerTest.java

This file was deleted.

0 comments on commit 1e3b0b5

Please sign in to comment.