better warning for errors in workflow step config (between steps)
diff --git a/core/src/main/java/org/apache/brooklyn/core/workflow/WorkflowExecutionContext.java b/core/src/main/java/org/apache/brooklyn/core/workflow/WorkflowExecutionContext.java
index deef3d0..28e19b5 100644
--- a/core/src/main/java/org/apache/brooklyn/core/workflow/WorkflowExecutionContext.java
+++ b/core/src/main/java/org/apache/brooklyn/core/workflow/WorkflowExecutionContext.java
@@ -1210,7 +1210,12 @@
} else if (onError != null && (!(onError instanceof Collection) || !((Collection)onError).isEmpty())) {
try {
- log.debug("Error in workflow '" + getName() + "' around step " + workflowStepReference(currentStepIndex) + ", running error handler");
+ if (currentStepInstance.getError()==null) {
+ log.warn("Error in workflow '" + getName() + "' around step " + workflowStepReference(currentStepIndex) + ", running error handler but likely this should be corrected in code -- " + Exceptions.collapseText(e));
+ log.debug("Trace of error:", e);
+ } else {
+ log.debug("Error in workflow '" + getName() + "' around step " + workflowStepReference(currentStepIndex) + ", running error handler");
+ }
Task<WorkflowErrorHandling.WorkflowErrorHandlingResult> workflowErrorHandlerTask = WorkflowErrorHandling.createWorkflowErrorHandlerTask(WorkflowExecutionContext.this, task, e);
errorHandlerTaskId = workflowErrorHandlerTask.getId();
WorkflowErrorHandling.WorkflowErrorHandlingResult result = DynamicTasks.queue(workflowErrorHandlerTask).getUnchecked();
diff --git a/core/src/test/java/org/apache/brooklyn/core/workflow/WorkflowPersistReplayErrorsTest.java b/core/src/test/java/org/apache/brooklyn/core/workflow/WorkflowPersistReplayErrorsTest.java
index e0635e1..73e242d 100644
--- a/core/src/test/java/org/apache/brooklyn/core/workflow/WorkflowPersistReplayErrorsTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/workflow/WorkflowPersistReplayErrorsTest.java
@@ -47,6 +47,7 @@
import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.collections.MutableSet;
import org.apache.brooklyn.util.core.config.ConfigBag;
+import org.apache.brooklyn.util.core.task.DeferredSupplier;
import org.apache.brooklyn.util.core.task.DynamicTasks;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.guava.Maybe;
@@ -649,7 +650,7 @@
}
@Test
- public void testSimpleErrorHandlerOnWorkflowFailing() throws IOException {
+ public void testSimpleErrorHandlerOnWorkflowFailingWorksAndDoesntLogWarning() throws IOException {
try (ClassLogWatcher logWatcher = new ClassLogWatcher(getClass().getPackage().getName()) {
@Override
protected void append(ILoggingEvent iLoggingEvent) {
@@ -679,6 +680,37 @@
}
@Test
+ public void testSimpleErrorHandlerOnWorkflowTriggeredByConditionAssertWorksAndDoesLog() throws IOException {
+ try (ClassLogWatcher logWatcher = new ClassLogWatcher(getClass().getPackage().getName()) {
+ @Override
+ protected void append(ILoggingEvent iLoggingEvent) {
+ if (iLoggingEvent.getLevel().isGreaterOrEqual(Level.INFO)) super.append(iLoggingEvent);
+ }
+ }) {
+ lastInvocation = runSteps(MutableList.of(MutableMap.of("condition",
+ MutableMap.of("assert", MutableMap.of("config", "missing_will_cause_to_throw")),
+ "step", "return true")),
+ null,
+ ConfigBag.newInstance().configure(
+ WorkflowEffector.ON_ERROR, MutableList.of("set-sensor had_error = yes", "fail rethrow message rethrown")));
+ Asserts.assertFailsWith(() -> lastInvocation.getUnchecked(), e -> {
+ Asserts.expectedFailureContains(e, "rethrown");
+ Asserts.assertThat(Exceptions.getCausalChain(e), ee -> ee.stream().filter(e2 -> e2.toString().contains("missing_will_cause_to_throw")).findAny().isPresent());
+ return true;
+ });
+
+ List<String> msgs = logWatcher.getMessages();
+ log.info("Error handler output:\n"+msgs.stream().collect(Collectors.joining("\n")));
+ Asserts.assertSize(msgs, 1);
+ Asserts.assertNotNull(msgs.stream().filter(s -> s.toLowerCase().matches(".*assertion.* failed.* config.*missing_will_cause_to_throw.*")).findAny().orElse(null));
+
+ Asserts.assertEquals(app.sensors().get(Sensors.newSensor(Object.class, "had_error")), "yes");
+ findSingleLastWorkflow();
+ Asserts.assertEquals(lastWorkflowContext.status, WorkflowExecutionContext.WorkflowStatus.ERROR);
+ }
+ }
+
+ @Test
public void testErrorHandlerListWithGotoExit() throws IOException {
try (ClassLogWatcher logWatcher = new ClassLogWatcher(getClass().getPackage().getName())) {
lastInvocation = runSteps(MutableList.of(