diff --git a/.hgtags b/.hgtags new file mode 100644 --- /dev/null +++ b/.hgtags @@ -0,0 +1,1 @@ +f1da3afc3521e0e1631ac19e09690bc0a241841a release v2.1 diff --git a/Implab/AbstractPromise.cs b/Implab/AbstractPromise.cs --- a/Implab/AbstractPromise.cs +++ b/Implab/AbstractPromise.cs @@ -27,10 +27,8 @@ namespace Implab { if ((m_mask & PromiseEventType.Success) != 0 && m_handler != null) { try { m_handler(); - } catch (Exception err) { - // avoid calling handler twice in case of error - if (m_error != null) - SignalError(err); + // Analysis disable once EmptyGeneralCatchClause + } catch { } } } @@ -55,8 +53,8 @@ namespace Implab { if (m_cancel != null) { try { m_cancel(reason); - } catch (Exception err) { - SignalError(err); + // Analysis disable once EmptyGeneralCatchClause + } catch { } } else if ( (m_mask & PromiseEventType.Cancelled) != 0 && m_handler != null) { try { diff --git a/Implab/AbstractPromiseT.cs b/Implab/AbstractPromiseT.cs --- a/Implab/AbstractPromiseT.cs +++ b/Implab/AbstractPromiseT.cs @@ -39,16 +39,14 @@ namespace Implab { if (m_success != null) { try { m_success(result); - } catch(Exception err) { - SignalError(err); + // Analysis disable once EmptyGeneralCatchClause + } catch { } } else if ((m_mask & PromiseEventType.Success) != 0 && m_handler != null) { try { m_handler(); - } catch(Exception err) { - // avoid calling handler twice in case of error - if (m_error != null) - SignalError(err); + // Analysis disable once EmptyGeneralCatchClause + } catch { } } } @@ -73,8 +71,8 @@ namespace Implab { if (m_cancel != null) { try { m_cancel(reason); - } catch (Exception err) { - SignalError(err); + // Analysis disable once EmptyGeneralCatchClause + } catch { } } else if ((m_mask & PromiseEventType.Cancelled) != 0 && m_handler != null) { try { diff --git a/Implab/ActionChainTask.cs b/Implab/ActionChainTask.cs --- a/Implab/ActionChainTask.cs +++ b/Implab/ActionChainTask.cs @@ -23,10 +23,8 @@ namespace Implab { var p = m_task(); p.On(SetResult, HandleErrorInternal, HandleCancelInternal); CancellationRequested(p.Cancel); - } catch (OperationCanceledException reason){ - HandleCancelInternal(reason); } catch(Exception err) { - HandleErrorInternal(err); + SetErrorInternal(err); } } } diff --git a/Implab/ActionChainTaskBase.cs b/Implab/ActionChainTaskBase.cs --- a/Implab/ActionChainTaskBase.cs +++ b/Implab/ActionChainTaskBase.cs @@ -36,10 +36,10 @@ namespace Implab { // отдавать ли результат или подтвердить отмену (или вернуть ошибку). CancellationRequested(p.Cancel); } catch (Exception err) { - HandleErrorInternal(err); + SetErrorInternal(err); } } else { - HandleErrorInternal(reason ?? new OperationCanceledException()); + SetCancelledInternal(reason); } } @@ -50,7 +50,7 @@ namespace Implab { p.On(SetResult, SetErrorInternal, SetCancelledInternal); CancellationRequested(p.Cancel); } catch (Exception err) { - SetErrorInternal(error); + SetErrorInternal(err); } } else { SetErrorInternal(error); diff --git a/Implab/ActionChainTaskT.cs b/Implab/ActionChainTaskT.cs --- a/Implab/ActionChainTaskT.cs +++ b/Implab/ActionChainTaskT.cs @@ -14,10 +14,8 @@ namespace Implab { var p = m_task(value); p.On(SetResult, HandleErrorInternal, HandleCancelInternal); CancellationRequested(p.Cancel); - } catch (OperationCanceledException reason) { - HandleCancelInternal(reason); } catch(Exception err) { - HandleErrorInternal(err); + SetErrorInternal(err); } } } diff --git a/Implab/ActionTask.cs b/Implab/ActionTask.cs --- a/Implab/ActionTask.cs +++ b/Implab/ActionTask.cs @@ -12,10 +12,8 @@ namespace Implab { try { m_task(); SetResult(); - } catch(OperationCanceledException reason) { - HandleCancelInternal(reason); } catch(Exception err) { - HandleErrorInternal(err); + SetErrorInternal(err); } } } diff --git a/Implab/ActionTaskBase.cs b/Implab/ActionTaskBase.cs --- a/Implab/ActionTaskBase.cs +++ b/Implab/ActionTaskBase.cs @@ -42,10 +42,10 @@ namespace Implab { m_cancel(error); SetResult(); } catch(Exception err) { - HandleErrorInternal(err); + SetErrorInternal(err); } } else { - HandleErrorInternal(error ?? new OperationCanceledException()); + SetCancelledInternal(error); } } } diff --git a/Implab/ActionTaskT.cs b/Implab/ActionTaskT.cs --- a/Implab/ActionTaskT.cs +++ b/Implab/ActionTaskT.cs @@ -12,10 +12,8 @@ namespace Implab { try { m_task(value); SetResult(); - } catch(OperationCanceledException reason) { - HandleCancelInternal(reason); } catch(Exception err) { - HandleErrorInternal(err); + SetErrorInternal(err); } } } diff --git a/Implab/Components/RunnableComponent.cs b/Implab/Components/RunnableComponent.cs --- a/Implab/Components/RunnableComponent.cs +++ b/Implab/Components/RunnableComponent.cs @@ -120,6 +120,20 @@ namespace Implab.Components { prev = m_pending; + Action errorOrCancel = e => { + if (e == null) + e = new OperationCanceledException(); + + lock (m_stateMachine) { + if (m_pending == promise) { + Move(Commands.Fail); + m_pending = null; + m_lastError = e; + } + } + throw new PromiseTransientException(e); + }; + promise = task.Then( () => { lock(m_stateMachine) { @@ -128,16 +142,9 @@ namespace Implab.Components { m_pending = null; } } - }, e => { - lock(m_stateMachine) { - if (m_pending == promise) { - Move(Commands.Fail); - m_pending = null; - m_lastError = e; - } - } - throw new PromiseTransientException(e); - } + }, + errorOrCancel, + errorOrCancel ); m_pending = promise; diff --git a/Implab/FuncChainTask.cs b/Implab/FuncChainTask.cs --- a/Implab/FuncChainTask.cs +++ b/Implab/FuncChainTask.cs @@ -15,10 +15,8 @@ namespace Implab { var operation = m_task(); operation.On(SetResult, HandleErrorInternal, HandleCancelInternal); CancellationRequested(operation.Cancel); - } catch (OperationCanceledException reason) { - HandleCancelInternal(reason); } catch (Exception err) { - HandleErrorInternal(err); + SetErrorInternal(err); } } } diff --git a/Implab/FuncChainTaskBase.cs b/Implab/FuncChainTaskBase.cs --- a/Implab/FuncChainTaskBase.cs +++ b/Implab/FuncChainTaskBase.cs @@ -43,10 +43,10 @@ namespace Implab { p.On(SetResult, HandleErrorInternal, SetCancelledInternal); CancellationRequested(p.Cancel); } catch (Exception err) { - HandleErrorInternal(err); + SetErrorInternal(err); } } else { - HandleErrorInternal(reason ?? new OperationCanceledException()); + SetCancelledInternal(reason); } } } diff --git a/Implab/FuncChainTaskT.cs b/Implab/FuncChainTaskT.cs --- a/Implab/FuncChainTaskT.cs +++ b/Implab/FuncChainTaskT.cs @@ -14,10 +14,8 @@ namespace Implab { var operation = m_task(value); operation.On(SetResult, HandleErrorInternal, SetCancelled); CancellationRequested(operation.Cancel); - } catch (OperationCanceledException reason) { - HandleCancelInternal(reason); } catch (Exception err) { - HandleErrorInternal(err); + SetErrorInternal(err); } } } diff --git a/Implab/FuncTask.cs b/Implab/FuncTask.cs --- a/Implab/FuncTask.cs +++ b/Implab/FuncTask.cs @@ -13,10 +13,8 @@ namespace Implab { if (m_task != null && LockCancelation()) { try { SetResult(m_task()); - } catch(OperationCanceledException reason) { - HandleCancelInternal(reason); } catch(Exception err) { - HandleErrorInternal(err); + SetErrorInternal(err); } } } diff --git a/Implab/FuncTaskBase.cs b/Implab/FuncTaskBase.cs --- a/Implab/FuncTaskBase.cs +++ b/Implab/FuncTaskBase.cs @@ -40,10 +40,10 @@ namespace Implab { try { SetResult(m_cancel(reason)); } catch (Exception err) { - HandleErrorInternal(err); + SetErrorInternal(err); } } else { - HandleErrorInternal(reason ?? new OperationCanceledException()); + SetCancelledInternal(reason); } } diff --git a/Implab/FuncTaskT.cs b/Implab/FuncTaskT.cs --- a/Implab/FuncTaskT.cs +++ b/Implab/FuncTaskT.cs @@ -12,10 +12,8 @@ namespace Implab { if (m_task != null && LockCancelation()) { try { SetResult(m_task(value)); - } catch(OperationCanceledException reason) { - HandleCancelInternal(reason); } catch(Exception err) { - HandleErrorInternal(err); + SetErrorInternal(err); } } }