From 68c4255a51c5da15b5776e26cbe6a1d1f39564d1 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Mon, 11 Mar 2013 21:49:04 +0600 Subject: [PATCH] updates proper error handling for razor script macros --- src/Umbraco.Web/umbraco.presentation/macro.cs | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Web/umbraco.presentation/macro.cs b/src/Umbraco.Web/umbraco.presentation/macro.cs index fd6bb43c45..41535a5a61 100644 --- a/src/Umbraco.Web/umbraco.presentation/macro.cs +++ b/src/Umbraco.Web/umbraco.presentation/macro.cs @@ -451,6 +451,18 @@ namespace umbraco macroControl = loadMacroXSLT(this, Model, pageElements); break; case (int)MacroTypes.Script: + + //error handler for partial views, is an action because we need to re-use it twice below + Action handleMacroScriptError = e => + { + LogHelper.WarnWithException("Error loading MacroEngine script (file: " + ScriptFile + ", Type: '" + Model.TypeName + "'", true, e); + + // Invoke any error handlers for this macro + var macroErrorEventArgs = new MacroErrorEventArgs { Name = Model.Name, Alias = Model.Alias, ItemKey = ScriptFile, Exception = e, Behaviour = UmbracoSettings.MacroErrorBehaviour }; + + macroControl = RaiseAndHandleErrorForBehavior("Error loading MacroEngine script (file: " + ScriptFile + ")", macroErrorEventArgs); + }; + try { TraceInfo("umbracoMacro", "MacroEngine script added (" + ScriptFile + ")"); @@ -458,10 +470,9 @@ namespace umbraco macroControl = new LiteralControl(result.Result); if (result.ResultException != null) { - // we'll throw the error if we run in release mode, show details if we're in release mode! renderFailed = true; - if (HttpContext.Current != null && !HttpContext.Current.IsDebuggingEnabled) - throw result.ResultException; + Exceptions.Add(result.ResultException); + handleMacroScriptError(result.ResultException); } break; } @@ -470,12 +481,7 @@ namespace umbraco renderFailed = true; Exceptions.Add(e); - LogHelper.WarnWithException("Error loading MacroEngine script (file: " + ScriptFile + ", Type: '" + Model.TypeName + "'", true, e); - - // Invoke any error handlers for this macro - var macroErrorEventArgs = new MacroErrorEventArgs {Name = Model.Name, Alias = Model.Alias, ItemKey = ScriptFile, Exception = e, Behaviour = UmbracoSettings.MacroErrorBehaviour}; - - macroControl = RaiseAndHandleErrorForBehavior("Error loading MacroEngine script (file: " + ScriptFile + ")", macroErrorEventArgs); + handleMacroScriptError(e); break; }