• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

AKlaus / DomainResult / 20653156657

02 Jan 2026 07:24AM UTC coverage: 84.232%. Remained the same
20653156657

push

github

web-flow
Removed old code after abandoning .NET 6

- Set `ImplicitUsings` for the project.
- Set `ContinuousIntegrationBuild` on NuGet packages.
- Removed unnecessary `NET6_0`, `NET6_0_OR_GREATER` and `NET7_0_OR_GREATER`

81 of 106 branches covered (76.42%)

Branch coverage included in aggregate %.

157 of 198 new or added lines in 8 files covered. (79.29%)

1 existing line in 1 file now uncovered.

341 of 395 relevant lines covered (86.33%)

23.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.82
/src/Common/Exceptions/DomainResultThrowCustomExceptionExtensions.cs
1
namespace DomainResults.Common.Exceptions;
2

3
/// <summary>
4
///     Extension methods to throw custom exceptions if <see cref="DomainResult.IsSuccess"/> is <value>false</value>.
5
/// </summary>
6
public static class DomainResultThrowCustomExceptionExtensions
7
{
8
        /// <summary>
9
        ///                Throw <typeparamref name="TE"/> if <paramref name="domainResult"/>'s <see cref="DomainResult.IsSuccess"/> is <value>false</value> 
10
        /// </summary>
11
        /// <param name="domainResult"> The IDomainResult to check </param>
12
        /// <param name="errMsg"> The error message </param>
13
        /// <typeparam name="TE">The exception type to throw if the <see cref="DomainResult.IsSuccess"/> is <value>false</value> </typeparam>
14
        public static void ThrowIfNoSuccess<TE>(this IDomainResult domainResult, string? errMsg = null) where TE: Exception, new()
15
        {
2✔
16
                if (domainResult.IsSuccess) 
2!
NEW
17
                        return;
×
18
                try { throw (TE)Activator.CreateInstance(typeof(TE), ConcatenateErrors(domainResult, errMsg)); }
4✔
19
                catch (MissingMethodException) { throw new TE(); }
3✔
NEW
20
        }
×
21
                
22
        ///  <summary>
23
        ///         Throw <typeparamref name="TE"/> if <paramref name="domainResult"/>'s <see cref="DomainResult.IsSuccess"/> is <value>false</value> 
24
        ///  </summary>
25
        ///  <param name="domainResult"> The IDomainResult to check </param>
26
        ///  <param name="errMsg"> The error message </param>
27
        ///  <returns> The value, if the <see cref="DomainResult.IsSuccess"/> is <value>true</value> </returns>
28
        ///  <typeparam name="TE">The exception type to throw if the <see cref="DomainResult.IsSuccess"/> is <value>false</value> </typeparam>
29
        ///  <typeparam name="T"> The value type of successful <paramref name="domainResult"/> </typeparam>
30
        public static T ThrowIfNoSuccess<T, TE>(this IDomainResult<T> domainResult, string? errMsg = null) where TE: Exception, new()
31
        {
2✔
32
                if (domainResult.IsSuccess)
2!
NEW
33
                        return domainResult.Value;
×
34
                try { throw (TE)Activator.CreateInstance(typeof(TE), ConcatenateErrors(domainResult, errMsg)); }
4✔
35
                catch (MissingMethodException) { throw new TE(); }
3✔
NEW
36
        }
×
37
        /// <summary>
38
        ///         Throw <typeparamref name="TE"/> if <paramref name="domainResult"/>'s <see cref="DomainResult.IsSuccess"/> is <value>false</value> 
39
        /// </summary>
40
        /// <param name="domainResult"> The <see cref="System.ValueTuple{T,IDomainResult}"/> to check </param>
41
        /// <param name="errMsg"> The error message </param>
42
        /// <returns> The value, if the <see cref="DomainResult.IsSuccess"/> is <value>true</value> </returns>
43
        /// <typeparam name="TE">The exception type to throw if the <see cref="DomainResult.IsSuccess"/> is <value>false</value> </typeparam>
44
        /// <typeparam name="T"> The value type of successful <paramref name="domainResult"/> </typeparam>
45
        public static T ThrowIfNoSuccess<T, TE>(this (T result, IDomainResult status) domainResult, string? errMsg = null) where TE: Exception, new()
46
        {
1✔
47
                var (result, status) = domainResult;
1✔
48
                if (status.IsSuccess)
1!
NEW
49
                        return result;
×
50
                try { throw (TE)Activator.CreateInstance(typeof(TE), ConcatenateErrors(status, errMsg)); }
2✔
NEW
51
                catch (MissingMethodException) { throw new TE(); }
×
NEW
52
        }
×
53
                
54
        /// <summary>
55
        ///         Throw <typeparamref name="TE"/> if <paramref name="domainResultTask"/>'s <see cref="DomainResult.IsSuccess"/> is <value>false</value> 
56
        /// </summary>
57
        /// <param name="domainResultTask"> The <see cref="System.Threading.Tasks.Task{IDomainResult}"/> to check </param>
58
        /// <param name="errMsg"> The error message </param>
59
        /// <exception cref="DomainResultException"> The thrown exception if the <see cref="DomainResult.IsSuccess"/> is <value>false</value> </exception>
60
        /// <typeparam name="TE">The exception type to throw if the <see cref="DomainResult.IsSuccess"/> is <value>false</value> </typeparam>
61
        public static async Task ThrowIfNoSuccess<TE>(this Task<IDomainResult> domainResultTask, string? errMsg = null) where TE: Exception, new()
62
        {                
2✔
63
                var domainResult = await domainResultTask.ConfigureAwait(true);
2✔
64
                if (domainResult.IsSuccess)
2!
NEW
65
                        return;
×
66
                try { throw (TE)Activator.CreateInstance(typeof(TE), ConcatenateErrors(domainResult, errMsg)); }
4✔
NEW
67
                catch (MissingMethodException) { throw new TE(); }
×
UNCOV
68
        }
×
69
        /// <summary>
70
        ///                Throw <typeparamref name="TE"/> if <paramref name="domainResultTask"/>'s <see cref="DomainResult.IsSuccess"/> is <value>false</value> 
71
        /// </summary>
72
        /// <param name="domainResultTask"> The <see cref="System.Threading.Tasks.Task{IDomainResult}"/> to check </param>
73
        /// <param name="errMsg"> The error message </param>
74
        /// <returns> The value, if the <see cref="DomainResult.IsSuccess"/> is <value>true</value> </returns>
75
        /// <typeparam name="TE">The exception type to throw if the <see cref="DomainResult.IsSuccess"/> is <value>false</value> </typeparam>
76
        /// <typeparam name="T"> The value type of successful <paramref name="domainResultTask"/> </typeparam>
77
        public static async Task<T> ThrowIfNoSuccess<T,TE>(this Task<IDomainResult<T>> domainResultTask, string? errMsg = null) where TE: Exception, new()
78
        {
2✔
79
                var domainResult = await domainResultTask.ConfigureAwait(true);
2✔
80
                if (domainResult.IsSuccess)
2!
NEW
81
                        return domainResult.Value;
×
82
                try { throw (TE)Activator.CreateInstance(typeof(TE), ConcatenateErrors(domainResult, errMsg)); }
4✔
83
                catch (MissingMethodException) { throw new TE(); }
3✔
NEW
84
        }
×
85
        /// <summary>
86
        ///                Throw <typeparamref name="TE"/> if <paramref name="domainResultTask"/>'s <see cref="DomainResult.IsSuccess"/> is <value>false</value> 
87
        /// </summary>
88
        /// <param name="domainResultTask"> The <see cref="System.Threading.Tasks.Task{IDomainResult}"/> to check </param>
89
        /// <param name="errMsg"> The error message </param>
90
        /// <returns> The value, if the <see cref="DomainResult.IsSuccess"/> is <value>true</value> </returns>
91
        /// <typeparam name="TE">The exception type to throw if the <see cref="DomainResult.IsSuccess"/> is <value>false</value> </typeparam>
92
        /// <typeparam name="T"> The value type of successful <paramref name="domainResultTask"/> </typeparam>
93
        public static async Task<T> ThrowIfNoSuccess<T,TE>(this Task<(T result, IDomainResult status)> domainResultTask, string? errMsg = null) where TE: Exception, new()
94
        {
2✔
95
                var (result, status) = await domainResultTask.ConfigureAwait(true);
2✔
96
                if (status.IsSuccess)
2!
NEW
97
                        return result;
×
98
                try { throw (TE)Activator.CreateInstance(typeof(TE), ConcatenateErrors(status, errMsg)); }
4✔
99
                catch (MissingMethodException) { throw new TE(); }
3✔
NEW
100
        }
×
101
                
102
        private static string ConcatenateErrors(IDomainResultBase result, string? baseErrMsg = null)
103
                => result.Error + (!string.IsNullOrWhiteSpace(baseErrMsg) ? ". "+baseErrMsg : "");
11!
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc