NickCraver / StackExchange.Exceptional

Error handler used for the Stack Exchange network
https://nickcraver.com/StackExchange.Exceptional/
Apache License 2.0
863 stars 171 forks source link

Logging null custom data breaks the exception info page #121

Closed xps closed 6 years ago

xps commented 6 years ago

Logging an exception like so:

new Exception("My exception).Log(HttpContext, customData: new Dictionary<string, string>
{
    { "MyData", null }
});

Correctly logs the exception but then when visualizing it in the Exceptional middleware, the details page throws the following exception:

System.ArgumentNullException: Value cannot be null.
Parameter name: input
   at System.Text.RegularExpressions.Regex.IsMatch(String input)
   at System.Text.RegularExpressions.Regex.IsMatch(String input, String pattern)
   at StackExchange.Exceptional.Internal.HtmlBase.Linkify(String s, String color)
   at StackExchange.Exceptional.Pages.ErrorDetailPage.<RenderInnerHtml>g__RenderKeyValueTable|6_1(IEnumerable<T> kvPairs, <>c__DisplayClass6_0& )
   at StackExchange.Exceptional.Pages.ErrorDetailPage.RenderInnerHtml(StringBuilder sb)
   at StackExchange.Exceptional.Pages.WebPage.RenderHtml(StringBuilder sb)
   at StackExchange.Exceptional.Internal.HtmlBase.Render()
   at StackExchange.Exceptional.ExceptionalMiddleware.<>c__DisplayClass7_0.<HandleRequestAsync>g__Page|2(WebPage page)
   at async StackExchange.Exceptional.ExceptionalMiddleware.<HandleRequestAsync>d__7.MoveNext()
   at async Bulgaro.Areas.Admin.Controllers.HomeController.<Exceptions>d__4.MoveNext()
   at async Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()
   at async Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at async Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__14.MoveNext()
   at async Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at async Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeFilterPipelineAsync>d__17.MoveNext()
   at async Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeAsync>d__15.MoveNext()
   at async Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
   at async Bulgaro.Misc.UserSessionLoggingMiddleware.<InvokeAsync>d__2.MoveNext()
   at StackExchange.Exceptional.ExceptionalMiddleware.<Invoke>d__6.MoveNext()
mmillican commented 6 years ago

@xps @NickCraver I was able to repro this with the latest. Adding the following to Html.BaseLinkify() solves the issue for me.

if (s.IsNullOrEmpty())
{
    return string.Empty;
}

If this is an acceptable fix, I can submit a PR tomorrow.

NickCraver commented 6 years ago

@mmillican absolutely!

mmillican commented 6 years ago

Great! Will submit later tonight.

NickCraver commented 6 years ago

Fixed via #123, thanks @mmillican!