Normalizing all catch (Exception ex) lines and adding exception fatality check where applicable, fixes #3949

This commit is contained in:
Lombiq
2015-09-07 00:17:57 +02:00
parent 14482162fd
commit a685517118
33 changed files with 217 additions and 66 deletions

View File

@@ -89,9 +89,9 @@ namespace Orchard.WarmupStarter {
var result = _initialization(application); var result = _initialization(application);
_initializationResult = result; _initializationResult = result;
} }
catch (Exception e) { catch (Exception ex) {
lock (_synLock) { lock (_synLock) {
_error = e; _error = ex;
_previousError = null; _previousError = null;
} }
} }

View File

@@ -17,6 +17,7 @@ using Orchard.UI.Navigation;
using Orchard.Utility; using Orchard.Utility;
using System; using System;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Exceptions;
namespace Orchard.Core.Navigation.Controllers { namespace Orchard.Core.Navigation.Controllers {
[ValidateInput(false)] [ValidateInput(false)]
@@ -179,6 +180,10 @@ namespace Orchard.Core.Navigation.Controllers {
return View(model); return View(model);
} }
catch (Exception exception) { catch (Exception exception) {
if (exception.IsFatal()) {
throw;
}
Logger.Error(T("Creating menu item failed: {0}", exception.Message).Text); Logger.Error(T("Creating menu item failed: {0}", exception.Message).Text);
Services.Notifier.Error(T("Creating menu item failed: {0}", exception.Message)); Services.Notifier.Error(T("Creating menu item failed: {0}", exception.Message));
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index")); return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));

View File

@@ -11,6 +11,7 @@ using Orchard.Security.Permissions;
using Orchard.UI; using Orchard.UI;
using Orchard.UI.Navigation; using Orchard.UI.Navigation;
using Orchard.Utility; using Orchard.Utility;
using Orchard.Exceptions;
namespace Orchard.Core.Navigation.Services { namespace Orchard.Core.Navigation.Services {
public class NavigationManager : INavigationManager { public class NavigationManager : INavigationManager {
@@ -152,6 +153,9 @@ namespace Orchard.Core.Navigation.Services {
items = builder.Build(); items = builder.Build();
} }
catch (Exception ex) { catch (Exception ex) {
if (ex.IsFatal()) {
throw;
}
Logger.Error(ex, "Unexpected error while querying a navigation provider. It was ignored. The menu provided by the provider may not be complete."); Logger.Error(ex, "Unexpected error while querying a navigation provider. It was ignored. The menu provided by the provider may not be complete.");
} }
if (items != null) { if (items != null) {
@@ -170,6 +174,9 @@ namespace Orchard.Core.Navigation.Services {
items = builder.Build(); items = builder.Build();
} }
catch (Exception ex) { catch (Exception ex) {
if (ex.IsFatal()) {
throw;
}
Logger.Error(ex, "Unexpected error while querying a menu provider. It was ignored. The menu provided by the provider may not be complete."); Logger.Error(ex, "Unexpected error while querying a menu provider. It was ignored. The menu provided by the provider may not be complete.");
} }
if (items != null) { if (items != null) {
@@ -188,6 +195,9 @@ namespace Orchard.Core.Navigation.Services {
imageSets = builder.BuildImageSets(); imageSets = builder.BuildImageSets();
} }
catch (Exception ex) { catch (Exception ex) {
if (ex.IsFatal()) {
throw;
}
Logger.Error(ex, "Unexpected error while querying a navigation provider. It was ignored. The menu provided by the provider may not be complete."); Logger.Error(ex, "Unexpected error while querying a navigation provider. It was ignored. The menu provided by the provider may not be complete.");
} }
if (imageSets != null) { if (imageSets != null) {

View File

@@ -9,6 +9,7 @@ using Orchard.Logging;
using Orchard.Services; using Orchard.Services;
using Orchard.Tasks; using Orchard.Tasks;
using Orchard.Tasks.Scheduling; using Orchard.Tasks.Scheduling;
using Orchard.Exceptions;
namespace Orchard.Core.Scheduling.Services { namespace Orchard.Core.Scheduling.Services {
[UsedImplicitly] [UsedImplicitly]
@@ -65,6 +66,9 @@ namespace Orchard.Core.Scheduling.Services {
} }
} }
catch (Exception ex) { catch (Exception ex) {
if (ex.IsFatal()) {
throw;
}
Logger.Warning(ex, "Unable to process scheduled task #{0} of type {1}", taskEntry.Id, taskEntry.Action); Logger.Warning(ex, "Unable to process scheduled task #{0} of type {1}", taskEntry.Id, taskEntry.Action);
_transactionManager.Cancel(); _transactionManager.Cancel();
} }

View File

@@ -11,6 +11,7 @@ using Orchard.Logging;
using Orchard.Security; using Orchard.Security;
using Orchard.Settings; using Orchard.Settings;
using Orchard.UI.Notify; using Orchard.UI.Notify;
using Orchard.Exceptions;
namespace Orchard.Core.Settings.Drivers { namespace Orchard.Core.Settings.Drivers {
[UsedImplicitly] [UsedImplicitly]
@@ -102,9 +103,12 @@ namespace Orchard.Core.Settings.Drivers {
using (request.GetResponse() as HttpWebResponse) {} using (request.GetResponse() as HttpWebResponse) {}
} }
} }
catch (Exception e) { catch (Exception ex) {
if (ex.IsFatal()) {
throw;
}
_notifier.Warning(T("The base url you entered could not be requested from current location.")); _notifier.Warning(T("The base url you entered could not be requested from current location."));
Logger.Warning(e, "Could not query base url: {0}", model.Site.BaseUrl); Logger.Warning(ex, "Could not query base url: {0}", model.Site.BaseUrl);
} }
} }
} }

View File

@@ -9,6 +9,7 @@ using Orchard.ContentManagement.MetaData.Services;
using Orchard.Core.Settings.Metadata.Records; using Orchard.Core.Settings.Metadata.Records;
using Orchard.Data; using Orchard.Data;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Exceptions;
namespace Orchard.Core.Settings.Metadata { namespace Orchard.Core.Settings.Metadata {
public class ContentDefinitionManager : Component, IContentDefinitionManager { public class ContentDefinitionManager : Component, IContentDefinitionManager {
@@ -282,6 +283,9 @@ namespace Orchard.Core.Settings.Metadata {
return XElement.Parse(settings); return XElement.Parse(settings);
} }
catch (Exception ex) { catch (Exception ex) {
if (ex.IsFatal()) {
throw;
}
Logger.Error(ex, "Unable to parse settings xml"); Logger.Error(ex, "Unable to parse settings xml");
return null; return null;
} }

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Exceptions;
namespace Orchard.Caching { namespace Orchard.Caching {
public class DefaultAsyncTokenProvider : IAsyncTokenProvider { public class DefaultAsyncTokenProvider : IAsyncTokenProvider {
@@ -37,9 +38,12 @@ namespace Orchard.Caching {
try { try {
_task(token => _taskTokens.Add(token)); _task(token => _taskTokens.Add(token));
} }
catch (Exception e) { catch (Exception ex) {
Logger.Error(e, "Error while monitoring extension files. Assuming extensions are not current."); if (ex.IsFatal()) {
_taskException = e; throw;
}
Logger.Error(ex, "Error while monitoring extension files. Assuming extensions are not current.");
_taskException = ex;
} }
finally { finally {
_isTaskFinished = true; _isTaskFinished = true;

View File

@@ -15,6 +15,7 @@ using Orchard.FileSystems.VirtualPath;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Tasks; using Orchard.Tasks;
using Orchard.Exceptions;
namespace Orchard.Commands { namespace Orchard.Commands {
@@ -94,19 +95,21 @@ namespace Orchard.Commands {
return CommandReturnCodes.Ok; return CommandReturnCodes.Ok;
} }
catch (OrchardCommandHostRetryException e) { catch (OrchardCommandHostRetryException ex) {
// Special "Retry" return code for our host // Special "Retry" return code for our host
output.WriteLine(T("{0} (Retrying...)", e.Message)); output.WriteLine(T("{0} (Retrying...)", ex.Message));
return CommandReturnCodes.Retry; return CommandReturnCodes.Retry;
} }
catch (Exception e) { catch (Exception ex) {
if (e is TargetInvocationException && if (ex.IsFatal()) {
e.InnerException != null) { throw;
// If this is an exception coming from reflection and there is an innerexception which is the actual one, redirect
e = e.InnerException;
} }
if (ex is TargetInvocationException &&
OutputException(output, T("Error executing command \"{0}\"", string.Join(" ", args)), e); ex.InnerException != null) {
// If this is an exception coming from reflection and there is an innerexception which is the actual one, redirect
ex = ex.InnerException;
}
OutputException(output, T("Error executing command \"{0}\"", string.Join(" ", args)), ex);
return CommandReturnCodes.Fail; return CommandReturnCodes.Fail;
} }
} }
@@ -116,13 +119,16 @@ namespace Orchard.Commands {
_hostContainer = CreateHostContainer(); _hostContainer = CreateHostContainer();
return CommandReturnCodes.Ok; return CommandReturnCodes.Ok;
} }
catch (OrchardCommandHostRetryException e) { catch (OrchardCommandHostRetryException ex) {
// Special "Retry" return code for our host // Special "Retry" return code for our host
output.WriteLine(T("{0} (Retrying...)", e.Message)); output.WriteLine(T("{0} (Retrying...)", ex.Message));
return CommandReturnCodes.Retry; return CommandReturnCodes.Retry;
} }
catch (Exception e) { catch (Exception ex) {
OutputException(output, T("Error starting up Orchard command line host"), e); if (ex.IsFatal()) {
throw;
}
OutputException(output, T("Error starting up Orchard command line host"), ex);
return CommandReturnCodes.Fail; return CommandReturnCodes.Fail;
} }
} }
@@ -135,8 +141,11 @@ namespace Orchard.Commands {
} }
return CommandReturnCodes.Ok; return CommandReturnCodes.Ok;
} }
catch (Exception e) { catch (Exception ex) {
OutputException(output, T("Error shutting down Orchard command line host"), e); if (ex.IsFatal()) {
throw;
}
OutputException(output, T("Error shutting down Orchard command line host"), ex);
return CommandReturnCodes.Fail; return CommandReturnCodes.Fail;
} }
} }

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Exceptions;
namespace Orchard.Commands { namespace Orchard.Commands {
public abstract class DefaultOrchardCommandHandler : ICommandHandler { public abstract class DefaultOrchardCommandHandler : ICommandHandler {
@@ -41,12 +42,15 @@ namespace Orchard.Commands {
object value = Convert.ChangeType(commandSwitch.Value, propertyInfo.PropertyType); object value = Convert.ChangeType(commandSwitch.Value, propertyInfo.PropertyType);
propertyInfo.SetValue(this, value, null/*index*/); propertyInfo.SetValue(this, value, null/*index*/);
} }
catch(Exception e) { catch(Exception ex) {
if (ex.IsFatal()) {
throw;
}
string message = T("Error converting value \"{0}\" to \"{1}\" for switch \"{2}\"", string message = T("Error converting value \"{0}\" to \"{1}\" for switch \"{2}\"",
LocalizedString.TextOrDefault(commandSwitch.Value, T("(empty)")), LocalizedString.TextOrDefault(commandSwitch.Value, T("(empty)")),
propertyInfo.PropertyType.FullName, propertyInfo.PropertyType.FullName,
commandSwitch.Key).Text; commandSwitch.Key).Text;
throw new InvalidOperationException(message, e); throw new InvalidOperationException(message, ex);
} }
} }

View File

@@ -3,6 +3,7 @@ using System.Linq;
using Orchard.Environment; using Orchard.Environment;
using Orchard.Environment.Features; using Orchard.Environment.Features;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Exceptions;
namespace Orchard.Data.Migration { namespace Orchard.Data.Migration {
/// <summary> /// <summary>
@@ -41,8 +42,11 @@ namespace Orchard.Data.Migration {
try { try {
_dataMigrationManager.Update(feature); _dataMigrationManager.Update(feature);
} }
catch (Exception e) { catch (Exception ex) {
Logger.Error("Could not run migrations automatically on " + feature, e); if (ex.IsFatal()) {
throw;
}
Logger.Error("Could not run migrations automatically on " + feature, ex);
} }
} }
} }

View File

@@ -9,6 +9,7 @@ using Orchard.Data.Migration.Schema;
using Orchard.Environment.Extensions; using Orchard.Environment.Extensions;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Exceptions;
namespace Orchard.Data.Migration { namespace Orchard.Data.Migration {
/// <summary> /// <summary>
@@ -123,6 +124,9 @@ namespace Orchard.Data.Migration {
current = (int)lookupTable[current].Invoke(migration, new object[0]); current = (int)lookupTable[current].Invoke(migration, new object[0]);
} }
catch (Exception ex) { catch (Exception ex) {
if (ex.IsFatal()) {
throw;
}
Logger.Error(ex, "An unexpected error occurred while applying migration on {0} from version {1}.", feature, current); Logger.Error(ex, "An unexpected error occurred while applying migration on {0} from version {1}.", feature, current);
throw; throw;
} }
@@ -139,10 +143,13 @@ namespace Orchard.Data.Migration {
dataMigrationRecord.Version = current; dataMigrationRecord.Version = current;
} }
} }
catch (Exception e) { catch (Exception ex) {
Logger.Error(e, "Error while running migration version {0} for {1}.", current, feature); if (ex.IsFatal()) {
throw;
}
Logger.Error(ex, "Error while running migration version {0} for {1}.", current, feature);
_transactionManager.Cancel(); _transactionManager.Cancel();
throw new OrchardException(T("Error while running migration version {0} for {1}.", current, feature), e); throw new OrchardException(T("Error while running migration version {0} for {1}.", current, feature), ex);
} }
} }

View File

@@ -1,6 +1,7 @@
using System; using System;
using Orchard.Data.Migration.Interpreters; using Orchard.Data.Migration.Interpreters;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Exceptions;
namespace Orchard.Data.Migration.Schema { namespace Orchard.Data.Migration.Schema {
public class SchemaBuilder { public class SchemaBuilder {
@@ -65,6 +66,9 @@ namespace Orchard.Data.Migration.Schema {
Run(sqlStatmentCommand); Run(sqlStatmentCommand);
return this; return this;
} catch (Exception ex) { } catch (Exception ex) {
if (ex.IsFatal()) {
throw;
}
throw new OrchardException(T("An unexpected error occured while executing the SQL statement: {0}", sql), ex); // Add the sql to the nested exception information throw new OrchardException(T("An unexpected error occured while executing the SQL statement: {0}", sql), ex); // Add the sql to the nested exception information
} }
} }

View File

@@ -11,6 +11,7 @@ using Orchard.Environment.ShellBuilders.Models;
using Orchard.FileSystems.AppData; using Orchard.FileSystems.AppData;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Utility; using Orchard.Utility;
using Orchard.Exceptions;
namespace Orchard.Data { namespace Orchard.Data {
public class SessionConfigurationCache : ISessionConfigurationCache { public class SessionConfigurationCache : ISessionConfigurationCache {
@@ -80,11 +81,11 @@ namespace Orchard.Data {
formatter.Serialize(stream, cache.Configuration); formatter.Serialize(stream, cache.Configuration);
} }
} }
catch (SerializationException e) { catch (SerializationException ex) {
//Note: This can happen when multiple processes/AppDomains try to save //Note: This can happen when multiple processes/AppDomains try to save
// the cached configuration at the same time. Only one concurrent // the cached configuration at the same time. Only one concurrent
// writer will win, and it's harmless for the other ones to fail. // writer will win, and it's harmless for the other ones to fail.
for (Exception scan = e; scan != null; scan = scan.InnerException) for (Exception scan = ex; scan != null; scan = scan.InnerException)
Logger.Warning("Error storing new NHibernate cache configuration: {0}", scan.Message); Logger.Warning("Error storing new NHibernate cache configuration: {0}", scan.Message);
} }
} }
@@ -118,8 +119,11 @@ namespace Orchard.Data {
}; };
} }
} }
catch (Exception e) { catch (Exception ex) {
for (var scan = e; scan != null; scan = scan.InnerException) if (ex.IsFatal()) {
throw;
}
for (var scan = ex; scan != null; scan = scan.InnerException)
Logger.Warning("Error reading the cached NHibernate configuration: {0}", scan.Message); Logger.Warning("Error reading the cached NHibernate configuration: {0}", scan.Message);
Logger.Information("A new one will be re-generated."); Logger.Information("A new one will be re-generated.");
return null; return null;

View File

@@ -13,6 +13,7 @@ using Orchard.Environment.Descriptor.Models;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Utility.Extensions; using Orchard.Utility.Extensions;
using Orchard.Exceptions;
namespace Orchard.Environment { namespace Orchard.Environment {
// All the event handlers that DefaultOrchardHost implements have to be declared in OrchardStarter // All the event handlers that DefaultOrchardHost implements have to be declared in OrchardStarter
@@ -140,8 +141,11 @@ namespace Orchard.Environment {
var context = CreateShellContext(settings); var context = CreateShellContext(settings);
ActivateShell(context); ActivateShell(context);
} }
catch (Exception e) { catch (Exception ex) {
Logger.Error(e, "A tenant could not be started: " + settings.Name); if (ex.IsFatal()) {
throw;
}
Logger.Error(ex, "A tenant could not be started: " + settings.Name);
} }
while (_processingEngine.AreTasksPending()) { while (_processingEngine.AreTasksPending()) {
Logger.Debug("Processing pending task after activate Shell"); Logger.Debug("Processing pending task after activate Shell");

View File

@@ -13,6 +13,7 @@ using Orchard.Tasks;
using Orchard.UI; using Orchard.UI;
using Orchard.WebApi.Routes; using Orchard.WebApi.Routes;
using Owin; using Owin;
using Orchard.Exceptions;
using IModelBinderProvider = Orchard.Mvc.ModelBinders.IModelBinderProvider; using IModelBinderProvider = Orchard.Mvc.ModelBinders.IModelBinderProvider;
namespace Orchard.Environment { namespace Orchard.Environment {
@@ -102,8 +103,12 @@ namespace Orchard.Environment {
try { try {
action(); action();
} }
catch(Exception e) { catch(Exception ex) {
Logger.Error(e, "An unexcepted error occured while terminating the Shell"); if (ex.IsFatal()) {
throw;
}
Logger.Error(ex, "An unexcepted error occured while terminating the Shell");
} }
} }
} }

View File

@@ -8,6 +8,7 @@ using Orchard.FileSystems.Dependencies;
using Orchard.FileSystems.VirtualPath; using Orchard.FileSystems.VirtualPath;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Exceptions;
namespace Orchard.Environment.Extensions.Compilers { namespace Orchard.Environment.Extensions.Compilers {
/// <summary> /// <summary>
@@ -106,10 +107,13 @@ namespace Orchard.Environment.Extensions.Compilers {
} }
} }
} }
catch (Exception e) { catch (Exception ex) {
if (ex.IsFatal()) {
throw;
}
//Note: we need to embed the "e.Message" in the exception text because //Note: we need to embed the "e.Message" in the exception text because
// ASP.NET build manager "swallows" inner exceptions from this method. // ASP.NET build manager "swallows" inner exceptions from this method.
throw new OrchardCoreException(T("Error compiling module \"{0}\" from file \"{1}\":\r\n{2}", moduleName, context.VirtualPath, e.Message), e); throw new OrchardCoreException(T("Error compiling module \"{0}\" from file \"{1}\":\r\n{2}", moduleName, context.VirtualPath, ex.Message), ex);
} }
} }

View File

@@ -9,6 +9,7 @@ using Orchard.Localization;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Utility; using Orchard.Utility;
using Orchard.Utility.Extensions; using Orchard.Utility.Extensions;
using Orchard.Exceptions;
namespace Orchard.Environment.Extensions { namespace Orchard.Environment.Extensions {
public class ExtensionManager : IExtensionManager { public class ExtensionManager : IExtensionManager {
@@ -119,6 +120,9 @@ namespace Orchard.Environment.Extensions {
}); });
} }
catch (Exception ex) { catch (Exception ex) {
if (ex.IsFatal()) {
throw;
}
Logger.Error(ex, "Error loading extension '{0}'", extensionId); Logger.Error(ex, "Error loading extension '{0}'", extensionId);
throw new OrchardException(T("Error while loading extension '{0}'.", extensionId), ex); throw new OrchardException(T("Error while loading extension '{0}'.", extensionId), ex);
} }

View File

@@ -8,6 +8,7 @@ using Orchard.FileSystems.WebSite;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Utility.Extensions; using Orchard.Utility.Extensions;
using Orchard.Exceptions;
namespace Orchard.Environment.Extensions.Folders { namespace Orchard.Environment.Extensions.Folders {
public class ExtensionHarvester : IExtensionHarvester { public class ExtensionHarvester : IExtensionHarvester {
@@ -98,6 +99,9 @@ namespace Orchard.Environment.Extensions.Folders {
} }
catch (Exception ex) { catch (Exception ex) {
// Ignore invalid module manifests // Ignore invalid module manifests
if (ex.IsFatal()) {
throw;
}
Logger.Error(ex, "The module '{0}' could not be loaded. It was ignored.", extensionId); Logger.Error(ex, "The module '{0}' could not be loaded. It was ignored.", extensionId);
_criticalErrorProvider.RegisterErrorMessage(T("The extension '{0}' manifest could not be loaded. It was ignored.", extensionId)); _criticalErrorProvider.RegisterErrorMessage(T("The extension '{0}' manifest could not be loaded. It was ignored.", extensionId));
} }

View File

@@ -4,6 +4,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Exceptions;
namespace Orchard.Environment { namespace Orchard.Environment {
public interface IAssemblyLoader { public interface IAssemblyLoader {
@@ -25,8 +27,11 @@ namespace Orchard.Environment {
try { try {
return _loadedAssemblies.GetOrAdd(this.ExtractAssemblyShortName(assemblyName), shortName => LoadWorker(shortName, assemblyName)); return _loadedAssemblies.GetOrAdd(this.ExtractAssemblyShortName(assemblyName), shortName => LoadWorker(shortName, assemblyName));
} }
catch (Exception e) { catch (Exception ex) {
Logger.Error(e, "Error loading assembly '{0}'", assemblyName); if (ex.IsFatal()) {
throw;
}
Logger.Error(ex, "Error loading assembly '{0}'", assemblyName);
return null; return null;
} }
} }

View File

@@ -53,8 +53,9 @@ namespace Orchard.Environment {
return BuildManager.GetCompiledAssembly(virtualPath); return BuildManager.GetCompiledAssembly(virtualPath);
} }
catch (Exception ex) { catch (Exception ex) {
if (ex.IsFatal()) throw; if (ex.IsFatal()) {
throw;
}
Logger.Warning(ex, "Error when compiling assembly under {0}.", virtualPath); Logger.Warning(ex, "Error when compiling assembly under {0}.", virtualPath);
return null; return null;
} }

View File

@@ -5,6 +5,7 @@ using Orchard.Environment.Descriptor;
using Orchard.Environment.Descriptor.Models; using Orchard.Environment.Descriptor.Models;
using Orchard.FileSystems.AppData; using Orchard.FileSystems.AppData;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Exceptions;
namespace Orchard.Environment { namespace Orchard.Environment {
public interface IHostLocalRestart { public interface IHostLocalRestart {
@@ -45,8 +46,11 @@ namespace Orchard.Environment {
try { try {
_appDataFolder.CreateFile(fileName, "Host Restart"); _appDataFolder.CreateFile(fileName, "Host Restart");
} }
catch(Exception e) { catch(Exception ex) {
Logger.Warning(e, "Error updating file '{0}'", fileName); if (ex.IsFatal()) {
throw;
}
Logger.Warning(ex, "Error updating file '{0}'", fileName);
} }
} }
} }

View File

@@ -6,6 +6,7 @@ using System.Timers;
using System.Web.Compilation; using System.Web.Compilation;
using Orchard.FileSystems.VirtualPath; using Orchard.FileSystems.VirtualPath;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Exceptions;
namespace Orchard.Environment { namespace Orchard.Environment {
public interface IViewsBackgroundCompilation { public interface IViewsBackgroundCompilation {
@@ -136,10 +137,13 @@ namespace Orchard.Environment {
if (firstFile != null) if (firstFile != null)
BuildManager.GetCompiledAssembly(firstFile); BuildManager.GetCompiledAssembly(firstFile);
} }
catch(Exception e) { catch(Exception ex) {
if (ex.IsFatal()) {
throw;
}
// Some views might not compile, this is ok and harmless in this // Some views might not compile, this is ok and harmless in this
// context of pre-compiling views. // context of pre-compiling views.
Logger.Information(e, "Compilation of directory '{0}' skipped", viewDirectory); Logger.Information(ex, "Compilation of directory '{0}' skipped", viewDirectory);
} }
stopwatch.Stop(); stopwatch.Stop();
Logger.Information("Directory '{0}' compiled in {1} msec", viewDirectory, stopwatch.ElapsedMilliseconds); Logger.Information("Directory '{0}' compiled in {1} msec", viewDirectory, stopwatch.ElapsedMilliseconds);

View File

@@ -7,6 +7,7 @@ using System.Reflection;
using Autofac.Features.Indexed; using Autofac.Features.Indexed;
using Orchard.Exceptions; using Orchard.Exceptions;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Exceptions;
namespace Orchard.Events { namespace Orchard.Events {
public class DefaultOrchardEventBus : IEventBus { public class DefaultOrchardEventBus : IEventBus {
@@ -53,6 +54,9 @@ namespace Orchard.Events {
return TryInvoke(eventHandler, messageName, interfaceName, methodName, eventData, out returnValue); return TryInvoke(eventHandler, messageName, interfaceName, methodName, eventData, out returnValue);
} }
catch (Exception exception) { catch (Exception exception) {
if (exception.IsFatal()) {
throw;
}
if (!_exceptionPolicy.HandleException(this, exception)) { if (!_exceptionPolicy.HandleException(this, exception)) {
throw; throw;
} }

View File

@@ -7,6 +7,7 @@ using Orchard.FileSystems.VirtualPath;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Validation; using Orchard.Validation;
using Orchard.Exceptions;
namespace Orchard.FileSystems.AppData { namespace Orchard.FileSystems.AppData {
public class AppDataFolder : IAppDataFolder { public class AppDataFolder : IAppDataFolder {
@@ -78,8 +79,11 @@ namespace Orchard.FileSystems.AppData {
try { try {
File.Delete(destinationFileName); File.Delete(destinationFileName);
} }
catch (Exception e) { catch (Exception ex) {
throw new OrchardCoreException(T("Unable to make room for file \"{0}\" in \"App_Data\" folder", destinationFileName), e); if (ex.IsFatal()) {
throw;
}
throw new OrchardCoreException(T("Unable to make room for file \"{0}\" in \"App_Data\" folder", destinationFileName), ex);
} }
} }

View File

@@ -5,6 +5,7 @@ using System.Xml.Linq;
using Orchard.Caching; using Orchard.Caching;
using Orchard.FileSystems.AppData; using Orchard.FileSystems.AppData;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Exceptions;
namespace Orchard.FileSystems.Dependencies { namespace Orchard.FileSystems.Dependencies {
/// <summary> /// <summary>
@@ -135,8 +136,11 @@ namespace Orchard.FileSystems.Dependencies {
return XDocument.Load(stream); return XDocument.Load(stream);
} }
} }
catch (Exception e) { catch (Exception ex) {
Logger.Information(e, "Error reading file '{0}'. Assuming empty.", persistancePath); if (ex.IsFatal()) {
throw;
}
Logger.Information(ex, "Error reading file '{0}'. Assuming empty.", persistancePath);
return new XDocument(); return new XDocument();
} }
} }

View File

@@ -6,6 +6,7 @@ using System.Web.Hosting;
using Orchard.Environment.Configuration; using Orchard.Environment.Configuration;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Validation; using Orchard.Validation;
using Orchard.Exceptions;
namespace Orchard.FileSystems.Media { namespace Orchard.FileSystems.Media {
public class FileSystemStorageProvider : IStorageProvider { public class FileSystemStorageProvider : IStorageProvider {
@@ -155,6 +156,9 @@ namespace Orchard.FileSystems.Media {
directoryInfo.Create(); directoryInfo.Create();
} }
catch (Exception ex) { catch (Exception ex) {
if (ex.IsFatal()) {
throw;
}
throw new ArgumentException(T("The folder could not be created at path: {0}. {1}", path, ex).ToString()); throw new ArgumentException(T("The folder could not be created at path: {0}. {1}", path, ex).ToString());
} }
} }

View File

@@ -5,6 +5,7 @@ using System.Linq;
using System.Web; using System.Web;
using System.Web.Hosting; using System.Web.Hosting;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Exceptions;
namespace Orchard.FileSystems.VirtualPath { namespace Orchard.FileSystems.VirtualPath {
public class DefaultVirtualPathProvider : IVirtualPathProvider { public class DefaultVirtualPathProvider : IVirtualPathProvider {
@@ -59,9 +60,12 @@ namespace Orchard.FileSystems.VirtualPath {
} }
return result; return result;
} }
catch (Exception e) { catch (Exception ex) {
if (ex.IsFatal()) {
throw;
}
// The initial path might have been invalid (e.g. path indicates a path outside the application root) // The initial path might have been invalid (e.g. path indicates a path outside the application root)
Logger.Information(e, "Path '{0}' cannot be made app relative", virtualPath); Logger.Information(ex, "Path '{0}' cannot be made app relative", virtualPath);
return null; return null;
} }
} }
@@ -156,8 +160,11 @@ namespace Orchard.FileSystems.VirtualPath {
try { try {
return FileExists(virtualPath); return FileExists(virtualPath);
} }
catch (Exception e) { catch (Exception ex) {
Logger.Information(e, "File '{0}' can not be checked for existence. Assuming doesn't exist.", virtualPath); if (ex.IsFatal()) {
throw;
}
Logger.Information(ex, "File '{0}' can not be checked for existence. Assuming doesn't exist.", virtualPath);
return false; return false;
} }
} }

View File

@@ -5,6 +5,7 @@ using Orchard.Logging;
using Orchard.Messaging.Events; using Orchard.Messaging.Events;
using Orchard.Messaging.Models; using Orchard.Messaging.Models;
using Orchard.ContentManagement.Records; using Orchard.ContentManagement.Records;
using Orchard.Exceptions;
namespace Orchard.Messaging.Services { namespace Orchard.Messaging.Services {
[Obsolete] [Obsolete]
@@ -40,8 +41,11 @@ namespace Orchard.Messaging.Services {
PrepareAndSend(type, properties, context); PrepareAndSend(type, properties, context);
} }
catch ( Exception e ) { catch (Exception ex) {
Logger.Error(e, "An error occured while sending the message {0}", type); if (ex.IsFatal()) {
throw;
}
Logger.Error(ex, "An error occured while sending the message {0}", type);
} }
} }
@@ -60,8 +64,11 @@ namespace Orchard.Messaging.Services {
PrepareAndSend(type, properties, context); PrepareAndSend(type, properties, context);
} }
catch (Exception e) { catch (Exception ex) {
Logger.Error(e, "An error occured while sending the message {0}", type); if (ex.IsFatal()) {
throw;
}
Logger.Error(ex, "An error occured while sending the message {0}", type);
} }
} }

View File

@@ -11,6 +11,7 @@ using System.Web.Routing;
using Autofac; using Autofac;
using Orchard.Mvc.Routes; using Orchard.Mvc.Routes;
using Orchard.Settings; using Orchard.Settings;
using Orchard.Exceptions;
namespace Orchard.Mvc { namespace Orchard.Mvc {
public class MvcModule : Module { public class MvcModule : Module {
@@ -31,7 +32,11 @@ namespace Orchard.Mvc {
// The "Request" property throws at application startup on IIS integrated pipeline mode. // The "Request" property throws at application startup on IIS integrated pipeline mode.
var req = HttpContext.Current.Request; var req = HttpContext.Current.Request;
} }
catch (Exception) { catch (Exception ex) {
if (ex.IsFatal()) {
throw;
}
return false; return false;
} }

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using Orchard.Data; using Orchard.Data;
using Orchard.Environment.Configuration; using Orchard.Environment.Configuration;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Exceptions;
namespace Orchard.Tasks { namespace Orchard.Tasks {
@@ -39,9 +40,13 @@ namespace Orchard.Tasks {
task.Sweep(); task.Sweep();
Logger.Information("Finished processing background task \"{0}\" on tenant \"{1}\".", taskName, _shellName); Logger.Information("Finished processing background task \"{0}\" on tenant \"{1}\".", taskName, _shellName);
} }
catch (Exception e) { catch (Exception ex) {
if (ex.IsFatal()) {
throw;
}
_transactionManager.Cancel(); _transactionManager.Cancel();
Logger.Error(e, "Error while processing background task \"{0}\" on tenant \"{1}\".", taskName, _shellName); Logger.Error(ex, "Error while processing background task \"{0}\" on tenant \"{1}\".", taskName, _shellName);
} }
} }
} }

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Timers; using System.Timers;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Exceptions;
namespace Orchard.Tasks { namespace Orchard.Tasks {
@@ -51,6 +52,10 @@ namespace Orchard.Tasks {
} }
} }
catch (Exception ex) { catch (Exception ex) {
if (ex.IsFatal()) {
throw;
}
Logger.Warning(ex, "Problem in background tasks"); Logger.Warning(ex, "Problem in background tasks");
} }
finally { finally {

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Web; using System.Web;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Exceptions;
namespace Orchard.Time { namespace Orchard.Time {
/// <summary> /// <summary>
@@ -31,8 +32,11 @@ namespace Orchard.Time {
TimeZone = TimeZoneInfo.FindSystemTimeZoneById(siteTimeZoneId) TimeZone = TimeZoneInfo.FindSystemTimeZoneById(siteTimeZoneId)
}; };
} }
catch(Exception e) { catch(Exception ex) {
Logger.Error(e, "TimeZone could not be loaded"); if (ex.IsFatal()) {
throw;
}
Logger.Error(ex, "TimeZone could not be loaded");
// if the database could not be updated in time, ignore this provider // if the database could not be updated in time, ignore this provider
return null; return null;

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Orchard.Logging; using Orchard.Logging;
using Orchard.UI.Notify; using Orchard.UI.Notify;
using Orchard.Exceptions;
namespace Orchard.UI.Admin.Notification { namespace Orchard.UI.Admin.Notification {
public class NotificationManager : INotificationManager { public class NotificationManager : INotificationManager {
@@ -22,8 +23,11 @@ namespace Orchard.UI.Admin.Notification {
try { try {
return n.GetNotifications(); return n.GetNotifications();
} }
catch(Exception e) { catch(Exception ex) {
Logger.Error("An unhandled exception was thrown while generating a notification: " + n.GetType(), e); if (ex.IsFatal()) {
throw;
}
Logger.Error("An unhandled exception was thrown while generating a notification: " + n.GetType(), ex);
return Enumerable.Empty<NotifyEntry>(); return Enumerable.Empty<NotifyEntry>();
} }
}).ToList(); }).ToList();