Skip to content

Commit a898080

Browse files
committed
fix more warnings
1 parent 43a5a77 commit a898080

28 files changed

Lines changed: 129 additions & 51 deletions

src/BuildingBlocks/Caching/DistributedCacheService.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,14 @@ private DistributedCacheEntryOptions BuildEntryOptions(TimeSpan? sliding)
9999
private string Normalize(string key)
100100
{
101101
if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key));
102-
if (key.StartsWith(_opts.KeyPrefix, StringComparison.Ordinal))
102+
var prefix = _opts.KeyPrefix ?? string.Empty;
103+
if (prefix.Length == 0)
103104
{
104-
return string.IsNullOrWhiteSpace(_opts.KeyPrefix) ? key :
105-
key;
106-
}
107-
else
108-
{
109-
return string.IsNullOrWhiteSpace(_opts.KeyPrefix) ? key :
110-
(_opts.KeyPrefix + key);
105+
return key;
111106
}
107+
108+
return key.StartsWith(prefix, StringComparison.Ordinal)
109+
? key
110+
: prefix + key;
112111
}
113112
}

src/BuildingBlocks/Core/Exceptions/CustomException.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Net;
1+
using System.Net;
2+
using System.Linq;
23

34
namespace FSH.Framework.Core.Exceptions;
45

@@ -18,9 +19,24 @@ public class CustomException : Exception
1819
/// </summary>
1920
public HttpStatusCode StatusCode { get; }
2021

22+
public CustomException()
23+
: this("An error occurred.", Enumerable.Empty<string>(), HttpStatusCode.InternalServerError)
24+
{
25+
}
26+
27+
public CustomException(string message)
28+
: this(message, Enumerable.Empty<string>(), HttpStatusCode.InternalServerError)
29+
{
30+
}
31+
32+
public CustomException(string message, Exception innerException)
33+
: this(message, innerException, Enumerable.Empty<string>(), HttpStatusCode.InternalServerError)
34+
{
35+
}
36+
2137
public CustomException(
2238
string message,
23-
IEnumerable<string>? errors = null,
39+
IEnumerable<string>? errors,
2440
HttpStatusCode statusCode = HttpStatusCode.InternalServerError)
2541
: base(message)
2642
{
@@ -31,11 +47,19 @@ public CustomException(
3147
public CustomException(
3248
string message,
3349
Exception innerException,
34-
IEnumerable<string>? errors = null,
50+
IEnumerable<string>? errors,
3551
HttpStatusCode statusCode = HttpStatusCode.InternalServerError)
3652
: base(message, innerException)
3753
{
3854
ErrorMessages = errors?.ToList() ?? new List<string>();
3955
StatusCode = statusCode;
4056
}
41-
}
57+
58+
public CustomException(
59+
string message,
60+
Exception innerException,
61+
HttpStatusCode statusCode)
62+
: this(message, innerException, Enumerable.Empty<string>(), statusCode)
63+
{
64+
}
65+
}

src/BuildingBlocks/Core/Exceptions/ForbiddenException.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ public ForbiddenException(string message, IEnumerable<string> errors)
2020
: base(message, errors.ToList(), HttpStatusCode.Forbidden)
2121
{
2222
}
23-
}
23+
24+
public ForbiddenException(string message, Exception innerException)
25+
: base(message, innerException, HttpStatusCode.Forbidden)
26+
{
27+
}
28+
}

src/BuildingBlocks/Core/Exceptions/NotFoundException.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ namespace FSH.Framework.Core.Exceptions;
77
/// </summary>
88
public class NotFoundException : CustomException
99
{
10+
public NotFoundException()
11+
: base("Resource not found.", Array.Empty<string>(), HttpStatusCode.NotFound)
12+
{
13+
}
14+
1015
public NotFoundException(string message)
1116
: base(message, Array.Empty<string>(), HttpStatusCode.NotFound)
1217
{
@@ -16,4 +21,9 @@ public NotFoundException(string message, IEnumerable<string> errors)
1621
: base(message, errors.ToList(), HttpStatusCode.NotFound)
1722
{
1823
}
19-
}
24+
25+
public NotFoundException(string message, Exception innerException)
26+
: base(message, innerException, HttpStatusCode.NotFound)
27+
{
28+
}
29+
}

src/BuildingBlocks/Core/Exceptions/UnauthorizedException.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ public UnauthorizedException(string message, IEnumerable<string> errors)
2020
: base(message, errors.ToList(), HttpStatusCode.Unauthorized)
2121
{
2222
}
23-
}
23+
24+
public UnauthorizedException(string message, Exception innerException)
25+
: base(message, innerException, HttpStatusCode.Unauthorized)
26+
{
27+
}
28+
}

src/BuildingBlocks/Eventing/Eventing.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<Nullable>enable</Nullable>
77
<RootNamespace>FSH.Framework.Eventing</RootNamespace>
88
<AssemblyName>FSH.Framework.Eventing</AssemblyName>
9+
<NoWarn>CA1711;CA1716;CA1031;S2139;S1066</NoWarn>
910
</PropertyGroup>
1011

1112
<ItemGroup>

src/BuildingBlocks/Eventing/InMemory/InMemoryEventBus.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ private async Task PublishSingleAsync(IIntegrationEvent @event, CancellationToke
5555

5656
foreach (var handler in handlers)
5757
{
58+
if (handler is null)
59+
{
60+
continue;
61+
}
62+
5863
var handlerName = handler.GetType().FullName ?? handler.GetType().Name;
5964

6065
if (inbox != null)

src/BuildingBlocks/Jobs/Extensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static IApplicationBuilder UseHeroJobDashboard(this IApplicationBuilder a
6666

6767
var hangfireOptions = config.GetSection(nameof(HangfireOptions)).Get<HangfireOptions>() ?? new HangfireOptions();
6868
var dashboardOptions = new DashboardOptions();
69-
dashboardOptions.AppPath = "https://fullstackhero.net/";
69+
dashboardOptions.AppPath = "/";
7070
dashboardOptions.Authorization = new[]
7171
{
7272
new HangfireCustomBasicAuthenticationFilter

src/BuildingBlocks/Jobs/LogJobFilter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ private static string FormatArguments(IReadOnlyList<object?> args)
124124
return "[]";
125125
}
126126

127+
#pragma warning disable CA1031 // best-effort formatting for diagnostics
127128
try
128129
{
129130
var rendered = args.Select(a => a?.ToString() ?? "null");
@@ -133,5 +134,6 @@ private static string FormatArguments(IReadOnlyList<object?> args)
133134
{
134135
return "[<unavailable>]";
135136
}
137+
#pragma warning restore CA1031
136138
}
137139
}

src/BuildingBlocks/Mailing/Services/SmtpMailService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public async Task SendAsync(MailRequest request, CancellationToken ct)
7979
catch (Exception ex)
8080
{
8181
_logger.LogError(ex, "An error occurred while sending email: {Message}", ex.Message);
82+
throw new InvalidOperationException("Failed to send email.", ex);
8283
}
8384
finally
8485
{

0 commit comments

Comments
 (0)