Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Brad 69 posts 97 karma points
    Mar 27, 2018 @ 20:28
    Brad
    0

    Cant get inline macroerrors to work on partialview .cshtml

    Hi Guys,

    I can't get the inline macro errors to work in Umbraco v7.7.4. I just get YSOD.

    Here is an example partial view CSHTML:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    @{ throw new Exception("Test") }

    debug=false customErrors = Off

  • Daniel Chenery 119 posts 465 karma points
    Mar 27, 2018 @ 21:00
  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Mar 28, 2018 @ 07:39
    Alex Skrypnyk
    0

    Hi Brad

    MacroErrors setting in /config/umbracoSettings.config should be set to throw like that:

    <MacroErrors>throw</MacroErrors>
    

    Thanks,

    Alex

  • Brad 69 posts 97 karma points
    Mar 28, 2018 @ 15:28
    Brad
    0

    It's set to inline, which is what I want. It's near the end of the project so we're trying to make sure one partialview can't take down the entire homepage. But inline seems to do nothing and I still get the global YSOD.

    Here is what it looks like:

  • Daniel Chenery 119 posts 465 karma points
    Mar 28, 2018 @ 15:33
    Daniel Chenery
    0

    If you're trying to prevent a YSOD, why not set it to silent?

    Alternatively, can you not update your Macro Partial View to do the relevant null checks to prevent this from happening?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Mar 28, 2018 @ 18:03
    Alex Skrypnyk
    0

    Wrap the code inside the macro to the try catch and handle exceptions.

  • Brad 69 posts 97 karma points
    Mar 28, 2018 @ 16:32
    Brad
    0

    I mean shouldn't inline work? I'd rather not use silent since the section would completely disappear and someone may not even realize it's missing.

    I don't think it's possible to code the partials in a way that anticipates every error possible..

    Edit: Just tested, silent doesn't work either.. I get a big YSOD.

  • Daniel Chenery 119 posts 465 karma points
    Mar 28, 2018 @ 22:04
    Daniel Chenery
    0

    I've not actually used that setting before, so I'm not sure why.

    I'm not too sure how you're macro is setup, but I would think null checks are possible. Even if they do get excessive. Could you provide an example?

    Like Alex mentions above though, at worst you could wrap the code in a try {} catch(){} block and then just put an error message in a p tag

  • Brad 69 posts 97 karma points
    Mar 29, 2018 @ 19:57
    Brad
    1

    Thanks for the idea. I just made some extension methods that wrapped the partial calls with a giant try catch:

    public static class HtmlHelperExtension {
    
    public static IHtmlString CachedPartial2(this System.Web.Mvc.HtmlHelper htmlHelper, string partialViewName, object model, int cachedSeconds) {
        try {
            return htmlHelper.CachedPartial(partialViewName, model, cachedSeconds);
        } catch (Exception ex) {
            return MvcHtmlString.Create("<p>There was an error rendering this section: " + partialViewName + "</p><div style='display:none'>" + ex.ToString() + "</div>");
        }
    }
    
    public static MvcHtmlString Partial2(this System.Web.Mvc.HtmlHelper htmlHelper, string partialViewName, object model) {
        try {
            return htmlHelper.Partial(partialViewName, model);
        } catch (Exception ex) {
            return MvcHtmlString.Create("<p>There was an error rendering this section: " + partialViewName + "</p><div style='display:none'>" + ex.ToString() + "</div>");
        }
    }
    
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft