From dbbdd16bb9881a53f8b129653655af31614df141 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Sat, 23 Mar 2013 02:34:34 +0600 Subject: [PATCH] Fixes: #U4-497 --- src/Umbraco.Web/umbraco.presentation/macro.cs | 66 ++++++++++++++----- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/src/Umbraco.Web/umbraco.presentation/macro.cs b/src/Umbraco.Web/umbraco.presentation/macro.cs index 41535a5a61..80fe808478 100644 --- a/src/Umbraco.Web/umbraco.presentation/macro.cs +++ b/src/Umbraco.Web/umbraco.presentation/macro.cs @@ -375,14 +375,12 @@ namespace umbraco case (int)MacroTypes.PartialView: //error handler for partial views, is an action because we need to re-use it twice below - Action handleError = e => + Func handleError = e => { LogHelper.WarnWithException("Error loading Partial View (file: " + ScriptFile + ")", true, e); - // Invoke any error handlers for this macro var macroErrorEventArgs = new MacroErrorEventArgs { Name = Model.Name, Alias = Model.Alias, ItemKey = Model.ScriptName, Exception = e, Behaviour = UmbracoSettings.MacroErrorBehaviour }; - - macroControl = RaiseAndHandleErrorForBehavior("Error loading Partial View script (file: " + ScriptFile + ")", macroErrorEventArgs); + return GetControlForErrorBehavior("Error loading Partial View script (file: " + ScriptFile + ")", macroErrorEventArgs); }; TraceInfo("umbracoMacro", "Partial View added (" + Model.TypeName + ")"); @@ -394,14 +392,25 @@ namespace umbraco { renderFailed = true; Exceptions.Add(result.ResultException); - handleError(result.ResultException); + macroControl = handleError(result.ResultException); + //if it is null, then we are supposed to throw the exception + if (macroControl == null) + { + throw result.ResultException; + } } } catch (Exception e) { renderFailed = true; - Exceptions.Add(e); - handleError(e); + Exceptions.Add(e); + macroControl = handleError(e); + //if it is null, then we are supposed to throw the (original) exception + // see: http://issues.umbraco.org/issue/U4-497 at the end + if (macroControl == null) + { + throw; + } } break; @@ -421,7 +430,13 @@ namespace umbraco // Invoke any error handlers for this macro var macroErrorEventArgs = new MacroErrorEventArgs {Name = Model.Name, Alias = Model.Alias, ItemKey = Model.TypeName, Exception = e, Behaviour = UmbracoSettings.MacroErrorBehaviour}; - macroControl = RaiseAndHandleErrorForBehavior("Error loading userControl '" + Model.TypeName + "'", macroErrorEventArgs); + macroControl = GetControlForErrorBehavior("Error loading userControl '" + Model.TypeName + "'", macroErrorEventArgs); + //if it is null, then we are supposed to throw the (original) exception + // see: http://issues.umbraco.org/issue/U4-497 at the end + if (macroControl == null) + { + throw; + } break; } @@ -443,7 +458,13 @@ namespace umbraco // Invoke any error handlers for this macro var macroErrorEventArgs = new MacroErrorEventArgs {Name = Model.Name, Alias = Model.Alias, ItemKey = Model.TypeAssembly, Exception = e, Behaviour = UmbracoSettings.MacroErrorBehaviour}; - macroControl = RaiseAndHandleErrorForBehavior("Error loading customControl (Assembly: " + Model.TypeAssembly + ", Type: '" + Model.TypeName + "'", macroErrorEventArgs); + macroControl = GetControlForErrorBehavior("Error loading customControl (Assembly: " + Model.TypeAssembly + ", Type: '" + Model.TypeName + "'", macroErrorEventArgs); + //if it is null, then we are supposed to throw the (original) exception + // see: http://issues.umbraco.org/issue/U4-497 at the end + if (macroControl == null) + { + throw; + } break; } @@ -453,14 +474,14 @@ namespace umbraco case (int)MacroTypes.Script: //error handler for partial views, is an action because we need to re-use it twice below - Action handleMacroScriptError = e => + Func 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); + return GetControlForErrorBehavior("Error loading MacroEngine script (file: " + ScriptFile + ")", macroErrorEventArgs); }; try @@ -472,7 +493,12 @@ namespace umbraco { renderFailed = true; Exceptions.Add(result.ResultException); - handleMacroScriptError(result.ResultException); + macroControl = handleMacroScriptError(result.ResultException); + //if it is null, then we are supposed to throw the exception + if (macroControl == null) + { + throw result.ResultException; + } } break; } @@ -481,7 +507,13 @@ namespace umbraco renderFailed = true; Exceptions.Add(e); - handleMacroScriptError(e); + macroControl = handleMacroScriptError(e); + //if it is null, then we are supposed to throw the (original) exception + // see: http://issues.umbraco.org/issue/U4-497 at the end + if (macroControl == null) + { + throw; + } break; } @@ -583,7 +615,7 @@ namespace umbraco /// /// /// - private Control RaiseAndHandleErrorForBehavior(string msg, MacroErrorEventArgs args) + private Control GetControlForErrorBehavior(string msg, MacroErrorEventArgs args) { OnError(args); @@ -595,7 +627,7 @@ namespace umbraco return new LiteralControl(""); case MacroErrorBehaviour.Throw: default: - throw args.Exception; + return null; } } @@ -793,7 +825,7 @@ namespace umbraco } var macroErrorEventArgs = new MacroErrorEventArgs {Name = Model.Name, Alias = Model.Alias, ItemKey = Model.Xslt, Exception = e, Behaviour = UmbracoSettings.MacroErrorBehaviour}; - return RaiseAndHandleErrorForBehavior("Error parsing XSLT file: \\xslt\\" + XsltFile, macroErrorEventArgs); + return GetControlForErrorBehavior("Error parsing XSLT file: \\xslt\\" + XsltFile, macroErrorEventArgs); } } catch (Exception e) @@ -803,7 +835,7 @@ namespace umbraco // Invoke any error handlers for this macro var macroErrorEventArgs = new MacroErrorEventArgs {Name = Model.Name, Alias = Model.Alias, ItemKey = Model.Xslt, Exception = e, Behaviour = UmbracoSettings.MacroErrorBehaviour}; - return RaiseAndHandleErrorForBehavior("Error reading XSLT file: \\xslt\\" + XsltFile, macroErrorEventArgs); + return GetControlForErrorBehavior("Error reading XSLT file: \\xslt\\" + XsltFile, macroErrorEventArgs); } }