Don’t send mail on an empty state
[rhynodge.git] / src / main / java / net / pterodactylus / rhynodge / engine / ReactionRunner.java
index ac04543..f4ae72e 100644 (file)
@@ -48,7 +48,7 @@ public class ReactionRunner implements Runnable {
                State state = runQuery();
                state = runStateThroughFilters(state);
                if (!state.success()) {
-                       logger.info(format("Reaction %s failed.", reaction.name()));
+                       logger.info(format("Reaction %s failed in %s.", reaction.name(), state));
                        saveStateWithIncreasedFailCount(state);
                        errorEmailAction.execute(createErrorOutput(reaction, state));
                        return;
@@ -77,14 +77,14 @@ public class ReactionRunner implements Runnable {
 
        private Output createErrorOutput(Reaction reaction, State state) {
                DefaultOutput output = new DefaultOutput(String.format("Error while processing “%s!”", reaction.name()));
-               output.addText("text/plain; charset=utf-8", createErrorEmailText(reaction, state));
-               output.addText("text/html; charset=utf-8", createErrorEmailText(reaction, state));
+               output.addText("text/plain", createErrorEmailText(reaction, state));
+               output.addText("text/html", createErrorEmailText(reaction, state));
                return output;
        }
 
        private String createErrorEmailText(Reaction reaction, State state) {
                StringBuilder emailText = new StringBuilder();
-               emailText.append(String.format("An error occured while processing “.”\n\n", reaction.name()));
+               emailText.append(String.format("An error occured while processing “%s.”\n\n", reaction.name()));
                appendExceptionToEmailText(state.exception(), emailText);
                return emailText.toString();
        }
@@ -119,9 +119,6 @@ public class ReactionRunner implements Runnable {
                                logger.debug(format("Filtering state through %s...", filter.getClass().getSimpleName()));
                                try {
                                        currentState = filter.filter(currentState);
-                                       if (currentState.success() && currentState.isEmpty()) {
-                                               errorEmailAction.execute(createEmptyStateOutput(reaction, state));
-                                       }
                                } catch (Throwable t1) {
                                        logger.warn(format("Error during filter %s for %s.", filter.getClass().getSimpleName(), reaction.name()), t1);
                                        return new FailedState(t1);
@@ -131,10 +128,4 @@ public class ReactionRunner implements Runnable {
                return currentState;
        }
 
-       private Output createEmptyStateOutput(Reaction reaction, State state) {
-               DefaultOutput defaultOutput = new DefaultOutput(String.format("Reached Empty State for “%s!”", reaction.name()));
-               defaultOutput.addText("text/plain; charset=utf-8", String.format("The %s for %s was empty.", state.getClass().getSimpleName(), reaction.name()));
-               return defaultOutput;
-       }
-
 }