(string.Format("Error creating usercontrol ({0})", fileName), true, e);
-
- return new LiteralControl(
- string.Format(
- "Error creating control ({0}).
Maybe file doesn't exists or the usercontrol has a cache directive, which is not allowed! See the tracestack for more information!
",
- fileName));
+ throw;
}
}
@@ -1802,5 +1844,31 @@ namespace umbraco
value = false;
return false;
}
+
+ #region Events
+
+ ///
+ /// The macro error event handler.
+ ///
+ public delegate void ErrorEventHandler(object sender, MacroErrorEventArgs e);
+
+ ///
+ /// Occurs when a macro error is raised.
+ ///
+ public static event ErrorEventHandler Error;
+
+ ///
+ /// Raises the event.
+ ///
+ /// The instance containing the event data.
+ protected virtual void OnError(MacroErrorEventArgs e)
+ {
+ if (Error != null)
+ {
+ Error(this, e);
+ }
+ }
+
+ #endregion
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/Macro.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/Macro.cs
index dc94b66cd8..db27764b80 100644
--- a/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/Macro.cs
+++ b/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/Macro.cs
@@ -183,6 +183,7 @@ namespace umbraco.presentation.templateControls
System.Web.HttpContext.Current.Trace.Warn("Template", "Result of macro " + tempMacro.Name + " is null");
} catch (Exception ee) {
System.Web.HttpContext.Current.Trace.Warn("Template", "Error adding macro " + tempMacro.Name, ee);
+ throw;
}
}
}
diff --git a/src/umbraco.MacroEngines/RazorCore/RazorMacroEngine.cs b/src/umbraco.MacroEngines/RazorCore/RazorMacroEngine.cs
index e30d8c5dca..83304f7ab2 100644
--- a/src/umbraco.MacroEngines/RazorCore/RazorMacroEngine.cs
+++ b/src/umbraco.MacroEngines/RazorCore/RazorMacroEngine.cs
@@ -171,11 +171,7 @@ namespace umbraco.MacroEngines
Success = false;
ResultException = exception;
HttpContext.Current.Trace.Warn("umbracoMacro", string.Format("Error Loading Razor Script (file: {0}) {1} {2}", macro.Name, exception.Message, exception.StackTrace));
- var loading = string.Format("Error loading Razor Script {0}", macro.ScriptName);
- if (GlobalSettings.DebugMode)
- loading = loading + exception.Message;
- loading = loading + "
";
- return loading;
+ throw;
}
}
diff --git a/src/umbraco.businesslogic/UmbracoSettings.cs b/src/umbraco.businesslogic/UmbracoSettings.cs
index 22133c3945..c7db9fdeb1 100644
--- a/src/umbraco.businesslogic/UmbracoSettings.cs
+++ b/src/umbraco.businesslogic/UmbracoSettings.cs
@@ -1,11 +1,7 @@
using System;
-using System.Diagnostics;
-using System.IO;
using System.Linq;
-using System.Web;
-using System.Web.Caching;
using System.Xml;
-using umbraco.BusinessLogic;
+using Umbraco.Core;
using System.Collections.Generic;
using umbraco.MacroEngines;
@@ -554,6 +550,18 @@ namespace umbraco
get { return Umbraco.Core.Configuration.UmbracoSettings.ResolveUrlsFromTextString; }
}
+ ///
+ /// This configuration setting defines how to handle macro errors:
+ /// - Inline - Show error within macro as text (default and current Umbraco 'normal' behavior)
+ /// - Silent - Suppress error and hide macro
+ /// - Throw - Throw an exception and invoke the global error handler (if one is defined, if not you'll get a YSOD)
+ ///
+ /// MacroErrorBehaviour enum defining how to handle macro errors.
+ public static MacroErrorBehaviour MacroErrorBehaviour
+ {
+ get { return Umbraco.Core.Configuration.UmbracoSettings.MacroErrorBehaviour; }
+ }
+
///
/// Configuration regarding webservices
///
diff --git a/src/umbraco.cms/businesslogic/events/EventArgs.cs b/src/umbraco.cms/businesslogic/events/EventArgs.cs
index 3514065cee..87942060f6 100644
--- a/src/umbraco.cms/businesslogic/events/EventArgs.cs
+++ b/src/umbraco.cms/businesslogic/events/EventArgs.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
+using Umbraco.Core;
using umbraco.cms.businesslogic.member;
using umbraco.cms.businesslogic.web;
@@ -61,5 +62,36 @@ namespace umbraco.cms.businesslogic {
{
public bool CancelChildren { get; set; }
}
-
+
+ // Provides information on the macro that caused an error
+ public class MacroErrorEventArgs : System.EventArgs
+ {
+ ///
+ /// Name of the faulting macro.
+ ///
+ public string Name { get; set; }
+
+ ///
+ /// Alias of the faulting macro.
+ ///
+ public string Alias { get; set; }
+
+ ///
+ /// Filename of the faulting macro.
+ ///
+ public string File { get; set; }
+
+ ///
+ /// Exception raised.
+ ///
+ public Exception Exception { get; set; }
+
+ ///
+ /// Gets or sets the desired behaviour when a matching macro causes an error. See
+ /// for definitions. By setting this in your event
+ /// you can override the default behaviour defined in UmbracoSettings.config.
+ ///
+ /// Macro error behaviour enum.
+ public MacroErrorBehaviour Behaviour { get; set; }
+ }
}