/// <summary> /// Stores the provided exception on this <seealso cref="CommandContext"/> instance. /// That exception will be rethrown at the end of closing the <seealso cref="CommandContext"/> instance. /// <para> /// If there is already an exception being stored, a 'masked exception' message will be logged. /// </para> /// </summary> public virtual void SetException(Exception exception) { if (_exception is null) { _exception = exception; } else { log.LogError("masked exception in command context. for root cause, see below as it will be rethrown later.", exception); LogMDC.Clear(); } }
/// <summary> /// /// </summary> /// <param name="flowNode"></param> protected internal virtual void ExecuteSynchronous(FlowNode flowNode) { // Execution listener if (CollectionUtil.IsNotEmpty(flowNode.ExecutionListeners)) { ExecuteExecutionListeners(flowNode, BaseExecutionListenerFields.EVENTNAME_START); } commandContext.HistoryManager.RecordActivityStart(execution); // Execute actual behavior IActivityBehavior activityBehavior = (IActivityBehavior)flowNode.Behavior; if (activityBehavior != null) { logger.LogDebug($"Executing activityBehavior {activityBehavior.GetType()} on activity '{flowNode.Id}' with execution {execution.Id}"); ProcessEngineConfigurationImpl processEngineConfiguration = Context.ProcessEngineConfiguration; if (processEngineConfiguration != null && processEngineConfiguration.EventDispatcher.Enabled) { processEngineConfiguration.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateActivityEvent(ActivitiEventType.ACTIVITY_STARTED, flowNode.Id, flowNode.Name, execution.Id, execution.ProcessInstanceId, execution.ProcessDefinitionId, flowNode)); } try { activityBehavior.Execute(execution); } catch (BpmnError error) { // re-throw business fault so that it can be caught by an Error Intermediate Event or Error Event Sub-Process in the process ErrorPropagation.PropagateError(error, execution); } catch (Exception e) { if (LogMDC.MDCEnabled) { LogMDC.PutMDCExecution(execution); } throw e; } } else { logger.LogDebug($"No activityBehavior on activity '{flowNode.Id}' with execution {execution.Id}"); } }