-
-
Notifications
You must be signed in to change notification settings - Fork 404
Add api to handle unhandled async rules exceptions #4727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rockfordlhotka
merged 7 commits into
main
from
fix/4725-handle-uncatched-async-rule-exceptions
Oct 4, 2025
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d8d3dbf
Fixes #4725
StefanOssendorf 097731b
Add docs
StefanOssendorf 16ea466
Add missing assignment line.
StefanOssendorf 9016f0b
Update Source/tests/Csla.test/ValidationRules/AsyncRuleTests.cs
StefanOssendorf e24d509
Update Source/Csla/Rules/BusinessRules.cs
StefanOssendorf 5c26004
Fix typo in class name
StefanOssendorf ab07cc2
Prevent test hos crash during test
StefanOssendorf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
Source/Csla/Rules/DontObserveUnhandledAsyncRuleExceptionHandler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace Csla.Rules; | ||
|
|
||
| internal class DontObserveUnhandledAsyncRuleExceptionHandler : IUnhandledAsyncRuleExceptionHandler | ||
| { | ||
| public bool CanHandle(Exception exception, IBusinessRuleBase executingRule) => false; | ||
| public ValueTask Handle(Exception exception, IBusinessRuleBase executingRule, IRuleContext ruleContext) => throw new NotSupportedException(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| namespace Csla.Rules; | ||
|
|
||
| /// <summary> | ||
| /// Represents an interface for handling exceptions raised by <see cref="IBusinessRuleAsync"/>. | ||
| /// </summary> | ||
| public interface IUnhandledAsyncRuleExceptionHandler | ||
| { | ||
| /// <summary> | ||
| /// Checks whether the given <paramref name="exception"/> and <paramref name="executingRule"/> can be handled. | ||
| /// </summary> | ||
| /// <param name="exception">The unhandled <see cref="Exception"/>.</param> | ||
| /// <param name="executingRule">The rule causing <paramref name="exception"/>.</param> | ||
| /// <returns><see langword="true"/> if the exception can be handled. Otherwise <see langword="false"/>.</returns> | ||
| bool CanHandle(Exception exception, IBusinessRuleBase executingRule); | ||
|
|
||
| /// <summary> | ||
| /// Handles the raised <paramref name="exception"/>. | ||
| /// </summary> | ||
| /// <param name="exception">The unhandled <see cref="Exception"/>.</param> | ||
| /// <param name="executingRule">The rule causing <paramref name="exception"/>.</param> | ||
| /// <param name="ruleContext">The associated <see cref="IRuleContext"/> to this rule run.</param> | ||
| /// <returns><see cref="ValueTask"/></returns> | ||
| ValueTask Handle(Exception exception, IBusinessRuleBase executingRule, IRuleContext ruleContext); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
Source/tests/Csla.test/ValidationRules/DelayedAsynRuleExceptionRoot.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="DelayedAsynRuleExceptionRoot.cs" company="Marimer LLC"> | ||
StefanOssendorf marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Copyright (c) Marimer LLC. All rights reserved. | ||
| // Website: https://cslanet.com | ||
| // </copyright> | ||
| // <summary>This only works on Silverlight because when run through NUnit it is not running</summary> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| using Csla.Core; | ||
| using Csla.Rules; | ||
|
|
||
| namespace Csla.Test.ValidationRules | ||
| { | ||
| [CslaImplementProperties] | ||
| internal partial class DelayedAsynRuleExceptionRoot : BusinessBase<DelayedAsynRuleExceptionRoot> | ||
| { | ||
| public partial TimeSpan ExceptionDelay { get; set; } | ||
|
|
||
| [Create, RunLocal] | ||
| private void Create() | ||
| { | ||
| _ = this; | ||
| } | ||
|
|
||
| protected override void AddBusinessRules() | ||
| { | ||
| base.AddBusinessRules(); | ||
| BusinessRules.AddRule(new RaiseExceptionRuleAsync(ExceptionDelayProperty)); | ||
| } | ||
|
|
||
|
|
||
| private class RaiseExceptionRuleAsync : BusinessRuleAsync | ||
| { | ||
| public RaiseExceptionRuleAsync(IPropertyInfo primaryProperty) : base(primaryProperty) | ||
| { | ||
| InputProperties.Add(primaryProperty); | ||
| } | ||
|
|
||
| protected override async Task ExecuteAsync(IRuleContext context) | ||
| { | ||
| var delay = context.GetInputValue<TimeSpan>(PrimaryProperty); | ||
|
|
||
| await Task.Delay(delay); | ||
|
|
||
| throw new InvalidOperationException("This is a test exception"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
33 changes: 33 additions & 0 deletions
33
Source/tests/Csla.test/ValidationRules/TestUnhandledAsyncRuleExceptionHandler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="TestUnhandledAsyncRuleExceptionHandler.cs" company="Marimer LLC"> | ||
| // Copyright (c) Marimer LLC. All rights reserved. | ||
| // Website: https://cslanet.com | ||
| // </copyright> | ||
| // <summary>This only works on Silverlight because when run through NUnit it is not running</summary> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| using Csla.Rules; | ||
|
|
||
| namespace Csla.Test.ValidationRules | ||
| { | ||
| internal class TestUnhandledAsyncRuleExceptionHandler : IUnhandledAsyncRuleExceptionHandler | ||
| { | ||
| public bool CanHandleResult { get; set; } = true; | ||
|
|
||
| public Action<Exception, IBusinessRuleBase> CanHandleInspector { get; set; } | ||
|
|
||
| public bool CanHandle(Exception exception, IBusinessRuleBase executingRule) | ||
| { | ||
| CanHandleInspector?.Invoke(exception, executingRule); | ||
| return CanHandleResult; | ||
| } | ||
|
|
||
|
|
||
| public Action<Exception, IBusinessRuleBase, IRuleContext> HandleInspector { get; set; } | ||
| public ValueTask Handle(Exception exception, IBusinessRuleBase executingRule, IRuleContext ruleContext) | ||
| { | ||
| HandleInspector?.Invoke(exception, executingRule, ruleContext); | ||
| return ValueTask.CompletedTask; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.