November Happy Hour will be moved to Thursday December 5th.

Triggering Alloy's ErrorHandlingContentRenderer

Vote:
 

Hello,

I was reviewing Alloy's error handling features and was trying to trigger the "nice" error alert, the partial view TemplateError.cshtml, that should be rendered in the body amongst other blocks instead of a server error (YSOD) when an exception is encountered rendering a block. However, I could not actually get this view to show up when forcing a few exceptions here and there, and I need some help.

I first started with a "block killer" by throwing an exception in the Jumbotron model on a property's get method. I then tried to throw an exception in the ContactBlock controller while it's creating its new ViewModel. My poison of choice was NullReferenceException which I confirmed is listed in ErrorHandlingContentRenderer. I would have expected either of these "block level" exceptions to have been caught and the TemplateError alert shown.

Maybe I'm just too tired and I'm throwing these wrong somehow, lol?, or I don't really follow how this particular error handling feature is supposed to work. Could you please let me know if I'm just looking at it the wrong way, are you able to trigger the error and if so can you show me how?

Thanks for any help :)

#206988
Sep 06, 2019 7:45
Vote:
 

Hi Allan,

You mentioned that you're not seeing the error partial when an exception is thrown but what are you seeing? A YSOD or just nothing where the block should be?

If you're running in debug mode, it's assumed you're a developer and would want to see the details of the error being thrown so will give you a YSOD.

If you're not in debug mode and you're not logged in to the CMS you should see nothing where your erroring block should be as you generally wouldn't want to show an error (even a non-fatal one) to an end user.

If you're not in debug mode but are logged in to the CMS you should see the error partial displayed in place of your erroring block.

#206995
Sep 06, 2019 10:22
Vote:
 

Thanks for getting back to me here. Some good questions, sorry I didn't think about if I was in Debug or not :) Everything you've mentioned is definitely what I would have expected for the error handling behaviour.

I tried a few more things since you mentioned it, but still in all cases I'm getting YSOD. I've tried various combinations of exception locations using "Start without debugging" and also using a "Release" solution configuration rather than "Debug", (if it matters in the vanilla project).

At this point I wouldn't put it past me to have either misunderstood what types of failures this error handling supports, or perhaps I have some build/cache issue. I might consider trying on a fresh Alloy project a little later.

#207055
Sep 06, 2019 21:45
Vote:
 

Have you tried explicitly changing from <compilation debug="true"> to <compilation debug="false"> in web.config? I've taken a look at an alloy site and neither "Start without debugging" nor a build in release mode seem to set that value.

#207065
Sep 09, 2019 10:39
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.