Skip to content

Commit

Permalink
Fixed issues from Sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasArdal committed Jan 9, 2024
1 parent 459f96c commit f8282d3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion samples/Elmah.Io.Functions.TimerTrigger60/Function1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Elmah.Io.Functions.TimerTrigger60
public class Function1
{
[FunctionName("Function1")]
public void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
public void Run([TimerTrigger("0 */5 * * * *", RunOnStartup = true)]TimerInfo myTimer, ILogger log)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
throw new Exception("An error happened");
Expand Down
6 changes: 3 additions & 3 deletions src/Elmah.Io.Functions/ElmahIoHeartbeatFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public class ElmahIoHeartbeatFilter : IFunctionInvocationFilter
{
private readonly ElmahIoFunctionOptions options;
private ElmahioAPI api;
internal static string _assemblyVersion = typeof(ElmahIoHeartbeatFilter).Assembly.GetName().Version.ToString();
private static string _assemblyVersion = typeof(ElmahIoHeartbeatFilter).Assembly.GetName().Version.ToString();
#pragma warning disable CS0618 // Type or member is obsolete
internal static string _functionsAssemblyVersion = typeof(IFunctionInvocationFilter).Assembly.GetName().Version.ToString();
private static string _functionsAssemblyVersion = typeof(IFunctionInvocationFilter).Assembly.GetName().Version.ToString();
#pragma warning restore CS0618 // Type or member is obsolete

/// <summary>
Expand All @@ -31,7 +31,7 @@ public ElmahIoHeartbeatFilter(IOptions<ElmahIoFunctionOptions> options)
{
this.options = options.Value;
if (string.IsNullOrWhiteSpace(this.options.ApiKey)) throw new ArgumentNullException(nameof(this.options.ApiKey));
if (this.options.LogId == null || this.options.LogId == Guid.Empty) throw new ArgumentNullException(nameof(this.options.LogId));
if (this.options.LogId == Guid.Empty) throw new ArgumentNullException(nameof(this.options.LogId));
if (string.IsNullOrWhiteSpace(this.options.HeartbeatId)) throw new ArgumentNullException(nameof(this.options.HeartbeatId));
}

Expand Down
19 changes: 11 additions & 8 deletions src/Elmah.Io.Functions/MessageShipper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

namespace Elmah.Io.Functions
{
internal class MessageShipper
internal static class MessageShipper
{
internal static string _assemblyVersion = typeof(MessageShipper).Assembly.GetName().Version.ToString();
private static string _assemblyVersion = typeof(MessageShipper).Assembly.GetName().Version.ToString();
#pragma warning disable CS0618 // Type or member is obsolete
internal static string _functionsAssemblyVersion = typeof(FunctionExceptionContext).Assembly.GetName().Version.ToString();
private static string _functionsAssemblyVersion = typeof(FunctionExceptionContext).Assembly.GetName().Version.ToString();

internal static IElmahioAPI elmahIoClient;

Expand All @@ -29,7 +29,7 @@ public static async Task Ship(FunctionExceptionContext exceptionContext, HttpCon
DateTime = DateTime.UtcNow,
Detail = Detail(exception),
Type = baseException?.GetType().FullName,
Title = baseException.Message,
Title = baseException?.Message ?? "An error happened",
Data = Data(exceptionContext),
Cookies = Cookies(context),
Form = Form(context),
Expand Down Expand Up @@ -139,14 +139,15 @@ private static List<Item> Form(HttpContext httpContext)
.Request?
.Form?
.Keys
.Select(k => new Item(k, httpContext.Request.Form[k])).ToList();
.Select(k => new Item(k, httpContext.Request.Form[k]))
.ToList() ?? new List<Item>();
}
catch (InvalidOperationException)
{
// Request not a form POST or similar
}

return null;
return new List<Item>();
}

private static List<Item> ServerVariables(HttpContext httpContext)
Expand All @@ -155,7 +156,8 @@ private static List<Item> ServerVariables(HttpContext httpContext)
.Request?
.Headers?
.Keys
.Select(k => new Item(k, httpContext.Request.Headers[k])).ToList();
.Select(k => new Item(k, httpContext.Request.Headers[k]))
.ToList() ?? new List<Item>();
}

private static List<Item> QueryString(HttpContext httpContext)
Expand All @@ -164,7 +166,8 @@ private static List<Item> QueryString(HttpContext httpContext)
.Request?
.Query?
.Keys
.Select(k => new Item(k, httpContext?.Request.Query[k])).ToList();
.Select(k => new Item(k, httpContext?.Request.Query[k]))
.ToList() ?? new List<Item>();
}

private static int? StatusCode(Exception exception, HttpContext context)
Expand Down

0 comments on commit f8282d3

Please sign in to comment.