Copied to clipboard

Flag this post as spam?

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


  • Andreas Gehrke 20 posts 44 karma points
    Nov 01, 2011 @ 16:12
    Andreas Gehrke
    1

    Hide uncaught exceptions in razor macros

    Hello

    How can I hide uncaught exceptions from being displayed on a production environment? Fx an external data source breaks down, and the following is displayed in my macro: 

    Error loading Razor Script MyRazorMacro.cshtml

    Yes, I could catch the exception, but what to do in case of a parse error?

    I of course have "umbracoDebugMode" disabled. Do I really need to implement my own IMacroEngine, or am I missing a setting?

    /Andreas

  • Rodion Novoselov 694 posts 859 karma points
    Nov 02, 2011 @ 09:36
    Rodion Novoselov
    0

    Hi. Razor macros are by their nature compiled on the first usage, so actually a partucalar error may be caused not only with a runtime exception but also with failed compilation. In the latter case I suspect that there's no at least a simple method to hide such an error besides just carefully testing your macro syntax before deployment to the production. As for usual runtime errors I think it's possible just to use conventional methods of error interception like trivial try/catch blocks and so on. 

  • Andreas Gehrke 20 posts 44 karma points
    Nov 03, 2011 @ 13:38
    Andreas Gehrke
    0

    Hello Rodion

    Thanks for your answer. The umbraco.MacroEngines.RazorMacroEngine which executes Razor macros has hardcoded the error text in case of a compilation or runtine error. So there's actually no way to prevent this text other than reimplementing the RazorMacroEngine. Shame..

  • Jonas Eriksson 930 posts 1825 karma points
    Nov 25, 2011 @ 21:58
    Jonas Eriksson
    0

    Niels is working on the macro engine currently afaiu, perhaps vote for this http://umbraco.codeplex.com/workitem/30617

  • Andreas Gehrke 20 posts 44 karma points
    Nov 25, 2011 @ 22:12
    Andreas Gehrke
    0

    Great :)

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Nov 28, 2011 @ 21:07
    Sebastiaan Janssen
    0

    Also see this topic for a way to hide the errors right now and a discussion of why I would not recommend it: http://our.umbraco.org/forum/developers/razor/26059-Switch-razor-error-and-red-box-off

  • Nuno Lourenço 4 posts 30 karma points
    Jan 18, 2012 @ 11:50
    Nuno Lourenço
    0

    You could also implement your own IHttpModule, and on that implementation add your own Filter stream. In that filter stream remove the

    Error loading RazorScriptMyRazorMacro.cshtml

    text/html so that it is not sent to the client. It is a not so desired solution, but...

    Cheers

Please Sign in or register to post replies

Write your reply to:

Draft