From a6855171184a28707ac7d5443719cdb2e23b50a0 Mon Sep 17 00:00:00 2001 From: Lombiq Date: Mon, 7 Sep 2015 00:17:57 +0200 Subject: [PATCH] Normalizing all catch (Exception ex) lines and adding exception fatality check where applicable, fixes #3949 --- src/Orchard.WarmupStarter/Starter.cs | 4 +- .../Navigation/Controllers/AdminController.cs | 5 +++ .../Navigation/Services/NavigationManager.cs | 10 +++++ .../Services/ScheduledTaskExecutor.cs | 4 ++ .../Drivers/SiteSettingsPartDriver.cs | 8 +++- .../Metadata/ContentDefinitionManager.cs | 4 ++ .../Caching/DefaultAsyncTokenProvider.cs | 10 +++-- src/Orchard/Commands/CommandHostAgent.cs | 39 ++++++++++++------- .../Commands/DefaultOrchardCommandHandler.cs | 8 +++- .../Data/Migration/AutomaticDataMigrations.cs | 8 +++- .../Data/Migration/DataMigrationManager.cs | 13 +++++-- .../Data/Migration/Schema/SchemaBuilder.cs | 4 ++ src/Orchard/Data/SessionConfigurationCache.cs | 12 ++++-- src/Orchard/Environment/DefaultOrchardHost.cs | 8 +++- .../Environment/DefaultOrchardShell.cs | 9 ++++- .../Compilers/DefaultExtensionCompiler.cs | 8 +++- .../Extensions/ExtensionManager.cs | 4 ++ .../Extensions/Folders/ExtensionHarvester.cs | 4 ++ src/Orchard/Environment/IAssemblyLoader.cs | 9 ++++- src/Orchard/Environment/IBuildManager.cs | 5 ++- src/Orchard/Environment/IHostLocalRestart.cs | 8 +++- .../Environment/ViewsBackgroundCompilation.cs | 8 +++- src/Orchard/Events/DefaultOrchardEventBus.cs | 4 ++ .../FileSystems/AppData/AppDataFolder.cs | 8 +++- .../DefaultExtensionDependenciesManager.cs | 8 +++- .../Media/FileSystemStorageProvider.cs | 4 ++ .../VirtualPath/DefaultVirtualPathProvider.cs | 15 +++++-- .../Services/DefaultMessageManager.cs | 15 +++++-- src/Orchard/Mvc/MvcModule.cs | 7 +++- src/Orchard/Tasks/BackgroundService.cs | 9 ++++- src/Orchard/Tasks/SweepGenerator.cs | 5 +++ src/Orchard/Time/SiteTimeZoneSelector.cs | 8 +++- .../Admin/Notification/NotificationManager.cs | 8 +++- 33 files changed, 217 insertions(+), 66 deletions(-) diff --git a/src/Orchard.WarmupStarter/Starter.cs b/src/Orchard.WarmupStarter/Starter.cs index ffa1f0763..b0b328da4 100644 --- a/src/Orchard.WarmupStarter/Starter.cs +++ b/src/Orchard.WarmupStarter/Starter.cs @@ -89,9 +89,9 @@ namespace Orchard.WarmupStarter { var result = _initialization(application); _initializationResult = result; } - catch (Exception e) { + catch (Exception ex) { lock (_synLock) { - _error = e; + _error = ex; _previousError = null; } } diff --git a/src/Orchard.Web/Core/Navigation/Controllers/AdminController.cs b/src/Orchard.Web/Core/Navigation/Controllers/AdminController.cs index 659a998db..a0b8087f2 100644 --- a/src/Orchard.Web/Core/Navigation/Controllers/AdminController.cs +++ b/src/Orchard.Web/Core/Navigation/Controllers/AdminController.cs @@ -17,6 +17,7 @@ using Orchard.UI.Navigation; using Orchard.Utility; using System; using Orchard.Logging; +using Orchard.Exceptions; namespace Orchard.Core.Navigation.Controllers { [ValidateInput(false)] @@ -179,6 +180,10 @@ namespace Orchard.Core.Navigation.Controllers { return View(model); } catch (Exception exception) { + if (exception.IsFatal()) { + throw; + } + Logger.Error(T("Creating menu item failed: {0}", exception.Message).Text); Services.Notifier.Error(T("Creating menu item failed: {0}", exception.Message)); return this.RedirectLocal(returnUrl, () => RedirectToAction("Index")); diff --git a/src/Orchard.Web/Core/Navigation/Services/NavigationManager.cs b/src/Orchard.Web/Core/Navigation/Services/NavigationManager.cs index bf7a529ea..a090a1bb2 100644 --- a/src/Orchard.Web/Core/Navigation/Services/NavigationManager.cs +++ b/src/Orchard.Web/Core/Navigation/Services/NavigationManager.cs @@ -11,6 +11,7 @@ using Orchard.Security.Permissions; using Orchard.UI; using Orchard.UI.Navigation; using Orchard.Utility; +using Orchard.Exceptions; namespace Orchard.Core.Navigation.Services { public class NavigationManager : INavigationManager { @@ -152,6 +153,9 @@ namespace Orchard.Core.Navigation.Services { items = builder.Build(); } 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."); } if (items != null) { @@ -170,6 +174,9 @@ namespace Orchard.Core.Navigation.Services { items = builder.Build(); } 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."); } if (items != null) { @@ -188,6 +195,9 @@ namespace Orchard.Core.Navigation.Services { imageSets = builder.BuildImageSets(); } 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."); } if (imageSets != null) { diff --git a/src/Orchard.Web/Core/Scheduling/Services/ScheduledTaskExecutor.cs b/src/Orchard.Web/Core/Scheduling/Services/ScheduledTaskExecutor.cs index 8485a9518..d4483aaab 100644 --- a/src/Orchard.Web/Core/Scheduling/Services/ScheduledTaskExecutor.cs +++ b/src/Orchard.Web/Core/Scheduling/Services/ScheduledTaskExecutor.cs @@ -9,6 +9,7 @@ using Orchard.Logging; using Orchard.Services; using Orchard.Tasks; using Orchard.Tasks.Scheduling; +using Orchard.Exceptions; namespace Orchard.Core.Scheduling.Services { [UsedImplicitly] @@ -65,6 +66,9 @@ namespace Orchard.Core.Scheduling.Services { } } catch (Exception ex) { + if (ex.IsFatal()) { + throw; + } Logger.Warning(ex, "Unable to process scheduled task #{0} of type {1}", taskEntry.Id, taskEntry.Action); _transactionManager.Cancel(); } diff --git a/src/Orchard.Web/Core/Settings/Drivers/SiteSettingsPartDriver.cs b/src/Orchard.Web/Core/Settings/Drivers/SiteSettingsPartDriver.cs index 6cba80e53..5591115e5 100644 --- a/src/Orchard.Web/Core/Settings/Drivers/SiteSettingsPartDriver.cs +++ b/src/Orchard.Web/Core/Settings/Drivers/SiteSettingsPartDriver.cs @@ -11,6 +11,7 @@ using Orchard.Logging; using Orchard.Security; using Orchard.Settings; using Orchard.UI.Notify; +using Orchard.Exceptions; namespace Orchard.Core.Settings.Drivers { [UsedImplicitly] @@ -102,9 +103,12 @@ namespace Orchard.Core.Settings.Drivers { 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.")); - Logger.Warning(e, "Could not query base url: {0}", model.Site.BaseUrl); + Logger.Warning(ex, "Could not query base url: {0}", model.Site.BaseUrl); } } } diff --git a/src/Orchard.Web/Core/Settings/Metadata/ContentDefinitionManager.cs b/src/Orchard.Web/Core/Settings/Metadata/ContentDefinitionManager.cs index e434318e1..16c1d1f78 100644 --- a/src/Orchard.Web/Core/Settings/Metadata/ContentDefinitionManager.cs +++ b/src/Orchard.Web/Core/Settings/Metadata/ContentDefinitionManager.cs @@ -9,6 +9,7 @@ using Orchard.ContentManagement.MetaData.Services; using Orchard.Core.Settings.Metadata.Records; using Orchard.Data; using Orchard.Logging; +using Orchard.Exceptions; namespace Orchard.Core.Settings.Metadata { public class ContentDefinitionManager : Component, IContentDefinitionManager { @@ -282,6 +283,9 @@ namespace Orchard.Core.Settings.Metadata { return XElement.Parse(settings); } catch (Exception ex) { + if (ex.IsFatal()) { + throw; + } Logger.Error(ex, "Unable to parse settings xml"); return null; } diff --git a/src/Orchard/Caching/DefaultAsyncTokenProvider.cs b/src/Orchard/Caching/DefaultAsyncTokenProvider.cs index b6769ec82..9f13571c0 100644 --- a/src/Orchard/Caching/DefaultAsyncTokenProvider.cs +++ b/src/Orchard/Caching/DefaultAsyncTokenProvider.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using Orchard.Logging; +using Orchard.Exceptions; namespace Orchard.Caching { public class DefaultAsyncTokenProvider : IAsyncTokenProvider { @@ -37,9 +38,12 @@ namespace Orchard.Caching { try { _task(token => _taskTokens.Add(token)); } - catch (Exception e) { - Logger.Error(e, "Error while monitoring extension files. Assuming extensions are not current."); - _taskException = e; + catch (Exception ex) { + if (ex.IsFatal()) { + throw; + } + Logger.Error(ex, "Error while monitoring extension files. Assuming extensions are not current."); + _taskException = ex; } finally { _isTaskFinished = true; diff --git a/src/Orchard/Commands/CommandHostAgent.cs b/src/Orchard/Commands/CommandHostAgent.cs index 6c7a955aa..04ab5a31a 100644 --- a/src/Orchard/Commands/CommandHostAgent.cs +++ b/src/Orchard/Commands/CommandHostAgent.cs @@ -15,6 +15,7 @@ using Orchard.FileSystems.VirtualPath; using Orchard.Localization; using Orchard.Logging; using Orchard.Tasks; +using Orchard.Exceptions; namespace Orchard.Commands { @@ -94,19 +95,21 @@ namespace Orchard.Commands { return CommandReturnCodes.Ok; } - catch (OrchardCommandHostRetryException e) { + catch (OrchardCommandHostRetryException ex) { // Special "Retry" return code for our host - output.WriteLine(T("{0} (Retrying...)", e.Message)); + output.WriteLine(T("{0} (Retrying...)", ex.Message)); return CommandReturnCodes.Retry; } - catch (Exception e) { - if (e is TargetInvocationException && - e.InnerException != null) { - // If this is an exception coming from reflection and there is an innerexception which is the actual one, redirect - e = e.InnerException; + catch (Exception ex) { + if (ex.IsFatal()) { + throw; } - - OutputException(output, T("Error executing command \"{0}\"", string.Join(" ", args)), e); + if (ex is TargetInvocationException && + 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; } } @@ -116,13 +119,16 @@ namespace Orchard.Commands { _hostContainer = CreateHostContainer(); return CommandReturnCodes.Ok; } - catch (OrchardCommandHostRetryException e) { + catch (OrchardCommandHostRetryException ex) { // Special "Retry" return code for our host - output.WriteLine(T("{0} (Retrying...)", e.Message)); + output.WriteLine(T("{0} (Retrying...)", ex.Message)); return CommandReturnCodes.Retry; } - catch (Exception e) { - OutputException(output, T("Error starting up Orchard command line host"), e); + catch (Exception ex) { + if (ex.IsFatal()) { + throw; + } + OutputException(output, T("Error starting up Orchard command line host"), ex); return CommandReturnCodes.Fail; } } @@ -135,8 +141,11 @@ namespace Orchard.Commands { } return CommandReturnCodes.Ok; } - catch (Exception e) { - OutputException(output, T("Error shutting down Orchard command line host"), e); + catch (Exception ex) { + if (ex.IsFatal()) { + throw; + } + OutputException(output, T("Error shutting down Orchard command line host"), ex); return CommandReturnCodes.Fail; } } diff --git a/src/Orchard/Commands/DefaultOrchardCommandHandler.cs b/src/Orchard/Commands/DefaultOrchardCommandHandler.cs index a5e8a3d89..7936ddef1 100644 --- a/src/Orchard/Commands/DefaultOrchardCommandHandler.cs +++ b/src/Orchard/Commands/DefaultOrchardCommandHandler.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using Orchard.Localization; +using Orchard.Exceptions; namespace Orchard.Commands { public abstract class DefaultOrchardCommandHandler : ICommandHandler { @@ -41,12 +42,15 @@ namespace Orchard.Commands { object value = Convert.ChangeType(commandSwitch.Value, propertyInfo.PropertyType); 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}\"", LocalizedString.TextOrDefault(commandSwitch.Value, T("(empty)")), propertyInfo.PropertyType.FullName, commandSwitch.Key).Text; - throw new InvalidOperationException(message, e); + throw new InvalidOperationException(message, ex); } } diff --git a/src/Orchard/Data/Migration/AutomaticDataMigrations.cs b/src/Orchard/Data/Migration/AutomaticDataMigrations.cs index 2a6e1ed49..9f3abddd9 100644 --- a/src/Orchard/Data/Migration/AutomaticDataMigrations.cs +++ b/src/Orchard/Data/Migration/AutomaticDataMigrations.cs @@ -3,6 +3,7 @@ using System.Linq; using Orchard.Environment; using Orchard.Environment.Features; using Orchard.Logging; +using Orchard.Exceptions; namespace Orchard.Data.Migration { /// @@ -41,8 +42,11 @@ namespace Orchard.Data.Migration { try { _dataMigrationManager.Update(feature); } - catch (Exception e) { - Logger.Error("Could not run migrations automatically on " + feature, e); + catch (Exception ex) { + if (ex.IsFatal()) { + throw; + } + Logger.Error("Could not run migrations automatically on " + feature, ex); } } } diff --git a/src/Orchard/Data/Migration/DataMigrationManager.cs b/src/Orchard/Data/Migration/DataMigrationManager.cs index 1ef6e33d7..02c6204f0 100644 --- a/src/Orchard/Data/Migration/DataMigrationManager.cs +++ b/src/Orchard/Data/Migration/DataMigrationManager.cs @@ -9,6 +9,7 @@ using Orchard.Data.Migration.Schema; using Orchard.Environment.Extensions; using Orchard.Localization; using Orchard.Logging; +using Orchard.Exceptions; namespace Orchard.Data.Migration { /// @@ -123,6 +124,9 @@ namespace Orchard.Data.Migration { current = (int)lookupTable[current].Invoke(migration, new object[0]); } catch (Exception ex) { + if (ex.IsFatal()) { + throw; + } Logger.Error(ex, "An unexpected error occurred while applying migration on {0} from version {1}.", feature, current); throw; } @@ -139,10 +143,13 @@ namespace Orchard.Data.Migration { dataMigrationRecord.Version = current; } } - catch (Exception e) { - Logger.Error(e, "Error while running migration version {0} for {1}.", current, feature); + catch (Exception ex) { + if (ex.IsFatal()) { + throw; + } + Logger.Error(ex, "Error while running migration version {0} for {1}.", current, feature); _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); } } diff --git a/src/Orchard/Data/Migration/Schema/SchemaBuilder.cs b/src/Orchard/Data/Migration/Schema/SchemaBuilder.cs index de5291a61..15e149f1e 100644 --- a/src/Orchard/Data/Migration/Schema/SchemaBuilder.cs +++ b/src/Orchard/Data/Migration/Schema/SchemaBuilder.cs @@ -1,6 +1,7 @@ using System; using Orchard.Data.Migration.Interpreters; using Orchard.Localization; +using Orchard.Exceptions; namespace Orchard.Data.Migration.Schema { public class SchemaBuilder { @@ -65,6 +66,9 @@ namespace Orchard.Data.Migration.Schema { Run(sqlStatmentCommand); return this; } 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 } } diff --git a/src/Orchard/Data/SessionConfigurationCache.cs b/src/Orchard/Data/SessionConfigurationCache.cs index 037f80801..30bae0547 100644 --- a/src/Orchard/Data/SessionConfigurationCache.cs +++ b/src/Orchard/Data/SessionConfigurationCache.cs @@ -11,6 +11,7 @@ using Orchard.Environment.ShellBuilders.Models; using Orchard.FileSystems.AppData; using Orchard.Logging; using Orchard.Utility; +using Orchard.Exceptions; namespace Orchard.Data { public class SessionConfigurationCache : ISessionConfigurationCache { @@ -80,11 +81,11 @@ namespace Orchard.Data { formatter.Serialize(stream, cache.Configuration); } } - catch (SerializationException e) { + catch (SerializationException ex) { //Note: This can happen when multiple processes/AppDomains try to save // the cached configuration at the same time. Only one concurrent // 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); } } @@ -118,8 +119,11 @@ namespace Orchard.Data { }; } } - catch (Exception e) { - for (var scan = e; scan != null; scan = scan.InnerException) + catch (Exception ex) { + 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.Information("A new one will be re-generated."); return null; diff --git a/src/Orchard/Environment/DefaultOrchardHost.cs b/src/Orchard/Environment/DefaultOrchardHost.cs index 977515317..c3d9fa782 100644 --- a/src/Orchard/Environment/DefaultOrchardHost.cs +++ b/src/Orchard/Environment/DefaultOrchardHost.cs @@ -13,6 +13,7 @@ using Orchard.Environment.Descriptor.Models; using Orchard.Localization; using Orchard.Logging; using Orchard.Utility.Extensions; +using Orchard.Exceptions; namespace Orchard.Environment { // All the event handlers that DefaultOrchardHost implements have to be declared in OrchardStarter @@ -140,8 +141,11 @@ namespace Orchard.Environment { var context = CreateShellContext(settings); ActivateShell(context); } - catch (Exception e) { - Logger.Error(e, "A tenant could not be started: " + settings.Name); + catch (Exception ex) { + if (ex.IsFatal()) { + throw; + } + Logger.Error(ex, "A tenant could not be started: " + settings.Name); } while (_processingEngine.AreTasksPending()) { Logger.Debug("Processing pending task after activate Shell"); diff --git a/src/Orchard/Environment/DefaultOrchardShell.cs b/src/Orchard/Environment/DefaultOrchardShell.cs index a679dec17..c4f42b786 100644 --- a/src/Orchard/Environment/DefaultOrchardShell.cs +++ b/src/Orchard/Environment/DefaultOrchardShell.cs @@ -13,6 +13,7 @@ using Orchard.Tasks; using Orchard.UI; using Orchard.WebApi.Routes; using Owin; +using Orchard.Exceptions; using IModelBinderProvider = Orchard.Mvc.ModelBinders.IModelBinderProvider; namespace Orchard.Environment { @@ -102,8 +103,12 @@ namespace Orchard.Environment { try { action(); } - catch(Exception e) { - Logger.Error(e, "An unexcepted error occured while terminating the Shell"); + catch(Exception ex) { + if (ex.IsFatal()) { + throw; + } + + Logger.Error(ex, "An unexcepted error occured while terminating the Shell"); } } } diff --git a/src/Orchard/Environment/Extensions/Compilers/DefaultExtensionCompiler.cs b/src/Orchard/Environment/Extensions/Compilers/DefaultExtensionCompiler.cs index 3dfc2d6af..488dcb90a 100644 --- a/src/Orchard/Environment/Extensions/Compilers/DefaultExtensionCompiler.cs +++ b/src/Orchard/Environment/Extensions/Compilers/DefaultExtensionCompiler.cs @@ -8,6 +8,7 @@ using Orchard.FileSystems.Dependencies; using Orchard.FileSystems.VirtualPath; using Orchard.Localization; using Orchard.Logging; +using Orchard.Exceptions; namespace Orchard.Environment.Extensions.Compilers { /// @@ -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 // 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); } } diff --git a/src/Orchard/Environment/Extensions/ExtensionManager.cs b/src/Orchard/Environment/Extensions/ExtensionManager.cs index 3701c9764..4dc8c02d3 100644 --- a/src/Orchard/Environment/Extensions/ExtensionManager.cs +++ b/src/Orchard/Environment/Extensions/ExtensionManager.cs @@ -9,6 +9,7 @@ using Orchard.Localization; using Orchard.Logging; using Orchard.Utility; using Orchard.Utility.Extensions; +using Orchard.Exceptions; namespace Orchard.Environment.Extensions { public class ExtensionManager : IExtensionManager { @@ -119,6 +120,9 @@ namespace Orchard.Environment.Extensions { }); } catch (Exception ex) { + if (ex.IsFatal()) { + throw; + } Logger.Error(ex, "Error loading extension '{0}'", extensionId); throw new OrchardException(T("Error while loading extension '{0}'.", extensionId), ex); } diff --git a/src/Orchard/Environment/Extensions/Folders/ExtensionHarvester.cs b/src/Orchard/Environment/Extensions/Folders/ExtensionHarvester.cs index a6ad55c72..38215b366 100644 --- a/src/Orchard/Environment/Extensions/Folders/ExtensionHarvester.cs +++ b/src/Orchard/Environment/Extensions/Folders/ExtensionHarvester.cs @@ -8,6 +8,7 @@ using Orchard.FileSystems.WebSite; using Orchard.Localization; using Orchard.Logging; using Orchard.Utility.Extensions; +using Orchard.Exceptions; namespace Orchard.Environment.Extensions.Folders { public class ExtensionHarvester : IExtensionHarvester { @@ -98,6 +99,9 @@ namespace Orchard.Environment.Extensions.Folders { } catch (Exception ex) { // Ignore invalid module manifests + if (ex.IsFatal()) { + throw; + } 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)); } diff --git a/src/Orchard/Environment/IAssemblyLoader.cs b/src/Orchard/Environment/IAssemblyLoader.cs index 410822a45..32722b5f1 100644 --- a/src/Orchard/Environment/IAssemblyLoader.cs +++ b/src/Orchard/Environment/IAssemblyLoader.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using Orchard.Logging; +using Orchard.Exceptions; + namespace Orchard.Environment { public interface IAssemblyLoader { @@ -25,8 +27,11 @@ namespace Orchard.Environment { try { return _loadedAssemblies.GetOrAdd(this.ExtractAssemblyShortName(assemblyName), shortName => LoadWorker(shortName, assemblyName)); } - catch (Exception e) { - Logger.Error(e, "Error loading assembly '{0}'", assemblyName); + catch (Exception ex) { + if (ex.IsFatal()) { + throw; + } + Logger.Error(ex, "Error loading assembly '{0}'", assemblyName); return null; } } diff --git a/src/Orchard/Environment/IBuildManager.cs b/src/Orchard/Environment/IBuildManager.cs index d9ac231ab..40b8c9aa8 100644 --- a/src/Orchard/Environment/IBuildManager.cs +++ b/src/Orchard/Environment/IBuildManager.cs @@ -53,8 +53,9 @@ namespace Orchard.Environment { return BuildManager.GetCompiledAssembly(virtualPath); } catch (Exception ex) { - if (ex.IsFatal()) throw; - + if (ex.IsFatal()) { + throw; + } Logger.Warning(ex, "Error when compiling assembly under {0}.", virtualPath); return null; } diff --git a/src/Orchard/Environment/IHostLocalRestart.cs b/src/Orchard/Environment/IHostLocalRestart.cs index 90a2371d2..f801e6efe 100644 --- a/src/Orchard/Environment/IHostLocalRestart.cs +++ b/src/Orchard/Environment/IHostLocalRestart.cs @@ -5,6 +5,7 @@ using Orchard.Environment.Descriptor; using Orchard.Environment.Descriptor.Models; using Orchard.FileSystems.AppData; using Orchard.Logging; +using Orchard.Exceptions; namespace Orchard.Environment { public interface IHostLocalRestart { @@ -45,8 +46,11 @@ namespace Orchard.Environment { try { _appDataFolder.CreateFile(fileName, "Host Restart"); } - catch(Exception e) { - Logger.Warning(e, "Error updating file '{0}'", fileName); + catch(Exception ex) { + if (ex.IsFatal()) { + throw; + } + Logger.Warning(ex, "Error updating file '{0}'", fileName); } } } diff --git a/src/Orchard/Environment/ViewsBackgroundCompilation.cs b/src/Orchard/Environment/ViewsBackgroundCompilation.cs index 67ae7ac1f..4d5e949d7 100644 --- a/src/Orchard/Environment/ViewsBackgroundCompilation.cs +++ b/src/Orchard/Environment/ViewsBackgroundCompilation.cs @@ -6,6 +6,7 @@ using System.Timers; using System.Web.Compilation; using Orchard.FileSystems.VirtualPath; using Orchard.Logging; +using Orchard.Exceptions; namespace Orchard.Environment { public interface IViewsBackgroundCompilation { @@ -136,10 +137,13 @@ namespace Orchard.Environment { if (firstFile != null) 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 // 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(); Logger.Information("Directory '{0}' compiled in {1} msec", viewDirectory, stopwatch.ElapsedMilliseconds); diff --git a/src/Orchard/Events/DefaultOrchardEventBus.cs b/src/Orchard/Events/DefaultOrchardEventBus.cs index d69d84023..adcab90d4 100644 --- a/src/Orchard/Events/DefaultOrchardEventBus.cs +++ b/src/Orchard/Events/DefaultOrchardEventBus.cs @@ -7,6 +7,7 @@ using System.Reflection; using Autofac.Features.Indexed; using Orchard.Exceptions; using Orchard.Localization; +using Orchard.Exceptions; namespace Orchard.Events { public class DefaultOrchardEventBus : IEventBus { @@ -53,6 +54,9 @@ namespace Orchard.Events { return TryInvoke(eventHandler, messageName, interfaceName, methodName, eventData, out returnValue); } catch (Exception exception) { + if (exception.IsFatal()) { + throw; + } if (!_exceptionPolicy.HandleException(this, exception)) { throw; } diff --git a/src/Orchard/FileSystems/AppData/AppDataFolder.cs b/src/Orchard/FileSystems/AppData/AppDataFolder.cs index 02e60e283..092ca9b45 100644 --- a/src/Orchard/FileSystems/AppData/AppDataFolder.cs +++ b/src/Orchard/FileSystems/AppData/AppDataFolder.cs @@ -7,6 +7,7 @@ using Orchard.FileSystems.VirtualPath; using Orchard.Localization; using Orchard.Logging; using Orchard.Validation; +using Orchard.Exceptions; namespace Orchard.FileSystems.AppData { public class AppDataFolder : IAppDataFolder { @@ -78,8 +79,11 @@ namespace Orchard.FileSystems.AppData { try { File.Delete(destinationFileName); } - catch (Exception e) { - throw new OrchardCoreException(T("Unable to make room for file \"{0}\" in \"App_Data\" folder", destinationFileName), e); + catch (Exception ex) { + if (ex.IsFatal()) { + throw; + } + throw new OrchardCoreException(T("Unable to make room for file \"{0}\" in \"App_Data\" folder", destinationFileName), ex); } } diff --git a/src/Orchard/FileSystems/Dependencies/DefaultExtensionDependenciesManager.cs b/src/Orchard/FileSystems/Dependencies/DefaultExtensionDependenciesManager.cs index c917c679d..1afd04077 100644 --- a/src/Orchard/FileSystems/Dependencies/DefaultExtensionDependenciesManager.cs +++ b/src/Orchard/FileSystems/Dependencies/DefaultExtensionDependenciesManager.cs @@ -5,6 +5,7 @@ using System.Xml.Linq; using Orchard.Caching; using Orchard.FileSystems.AppData; using Orchard.Logging; +using Orchard.Exceptions; namespace Orchard.FileSystems.Dependencies { /// @@ -135,8 +136,11 @@ namespace Orchard.FileSystems.Dependencies { return XDocument.Load(stream); } } - catch (Exception e) { - Logger.Information(e, "Error reading file '{0}'. Assuming empty.", persistancePath); + catch (Exception ex) { + if (ex.IsFatal()) { + throw; + } + Logger.Information(ex, "Error reading file '{0}'. Assuming empty.", persistancePath); return new XDocument(); } } diff --git a/src/Orchard/FileSystems/Media/FileSystemStorageProvider.cs b/src/Orchard/FileSystems/Media/FileSystemStorageProvider.cs index 5b6200657..ebcde7b54 100644 --- a/src/Orchard/FileSystems/Media/FileSystemStorageProvider.cs +++ b/src/Orchard/FileSystems/Media/FileSystemStorageProvider.cs @@ -6,6 +6,7 @@ using System.Web.Hosting; using Orchard.Environment.Configuration; using Orchard.Localization; using Orchard.Validation; +using Orchard.Exceptions; namespace Orchard.FileSystems.Media { public class FileSystemStorageProvider : IStorageProvider { @@ -155,6 +156,9 @@ namespace Orchard.FileSystems.Media { directoryInfo.Create(); } catch (Exception ex) { + if (ex.IsFatal()) { + throw; + } throw new ArgumentException(T("The folder could not be created at path: {0}. {1}", path, ex).ToString()); } } diff --git a/src/Orchard/FileSystems/VirtualPath/DefaultVirtualPathProvider.cs b/src/Orchard/FileSystems/VirtualPath/DefaultVirtualPathProvider.cs index 85a295d1b..4c2941e91 100644 --- a/src/Orchard/FileSystems/VirtualPath/DefaultVirtualPathProvider.cs +++ b/src/Orchard/FileSystems/VirtualPath/DefaultVirtualPathProvider.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Web; using System.Web.Hosting; using Orchard.Logging; +using Orchard.Exceptions; namespace Orchard.FileSystems.VirtualPath { public class DefaultVirtualPathProvider : IVirtualPathProvider { @@ -59,9 +60,12 @@ namespace Orchard.FileSystems.VirtualPath { } 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) - Logger.Information(e, "Path '{0}' cannot be made app relative", virtualPath); + Logger.Information(ex, "Path '{0}' cannot be made app relative", virtualPath); return null; } } @@ -156,8 +160,11 @@ namespace Orchard.FileSystems.VirtualPath { try { return FileExists(virtualPath); } - catch (Exception e) { - Logger.Information(e, "File '{0}' can not be checked for existence. Assuming doesn't exist.", virtualPath); + catch (Exception ex) { + if (ex.IsFatal()) { + throw; + } + Logger.Information(ex, "File '{0}' can not be checked for existence. Assuming doesn't exist.", virtualPath); return false; } } diff --git a/src/Orchard/Messaging/Services/DefaultMessageManager.cs b/src/Orchard/Messaging/Services/DefaultMessageManager.cs index 8e2911857..1495f9e37 100644 --- a/src/Orchard/Messaging/Services/DefaultMessageManager.cs +++ b/src/Orchard/Messaging/Services/DefaultMessageManager.cs @@ -5,6 +5,7 @@ using Orchard.Logging; using Orchard.Messaging.Events; using Orchard.Messaging.Models; using Orchard.ContentManagement.Records; +using Orchard.Exceptions; namespace Orchard.Messaging.Services { [Obsolete] @@ -40,8 +41,11 @@ namespace Orchard.Messaging.Services { PrepareAndSend(type, properties, context); } - catch ( Exception e ) { - Logger.Error(e, "An error occured while sending the message {0}", type); + catch (Exception ex) { + 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); } - catch (Exception e) { - Logger.Error(e, "An error occured while sending the message {0}", type); + catch (Exception ex) { + if (ex.IsFatal()) { + throw; + } + Logger.Error(ex, "An error occured while sending the message {0}", type); } } diff --git a/src/Orchard/Mvc/MvcModule.cs b/src/Orchard/Mvc/MvcModule.cs index 4125c4706..33cc7176d 100644 --- a/src/Orchard/Mvc/MvcModule.cs +++ b/src/Orchard/Mvc/MvcModule.cs @@ -11,6 +11,7 @@ using System.Web.Routing; using Autofac; using Orchard.Mvc.Routes; using Orchard.Settings; +using Orchard.Exceptions; namespace Orchard.Mvc { public class MvcModule : Module { @@ -31,7 +32,11 @@ namespace Orchard.Mvc { // The "Request" property throws at application startup on IIS integrated pipeline mode. var req = HttpContext.Current.Request; } - catch (Exception) { + catch (Exception ex) { + if (ex.IsFatal()) { + throw; + } + return false; } diff --git a/src/Orchard/Tasks/BackgroundService.cs b/src/Orchard/Tasks/BackgroundService.cs index d796a2d0d..36d55b252 100644 --- a/src/Orchard/Tasks/BackgroundService.cs +++ b/src/Orchard/Tasks/BackgroundService.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Orchard.Data; using Orchard.Environment.Configuration; using Orchard.Logging; +using Orchard.Exceptions; namespace Orchard.Tasks { @@ -39,9 +40,13 @@ namespace Orchard.Tasks { task.Sweep(); Logger.Information("Finished processing background task \"{0}\" on tenant \"{1}\".", taskName, _shellName); } - catch (Exception e) { + catch (Exception ex) { + if (ex.IsFatal()) { + throw; + } + _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); } } } diff --git a/src/Orchard/Tasks/SweepGenerator.cs b/src/Orchard/Tasks/SweepGenerator.cs index feb8a3f0e..44429e50b 100644 --- a/src/Orchard/Tasks/SweepGenerator.cs +++ b/src/Orchard/Tasks/SweepGenerator.cs @@ -1,6 +1,7 @@ using System; using System.Timers; using Orchard.Logging; +using Orchard.Exceptions; namespace Orchard.Tasks { @@ -51,6 +52,10 @@ namespace Orchard.Tasks { } } catch (Exception ex) { + if (ex.IsFatal()) { + throw; + } + Logger.Warning(ex, "Problem in background tasks"); } finally { diff --git a/src/Orchard/Time/SiteTimeZoneSelector.cs b/src/Orchard/Time/SiteTimeZoneSelector.cs index 28068b213..366718216 100644 --- a/src/Orchard/Time/SiteTimeZoneSelector.cs +++ b/src/Orchard/Time/SiteTimeZoneSelector.cs @@ -1,6 +1,7 @@ using System; using System.Web; using Orchard.Logging; +using Orchard.Exceptions; namespace Orchard.Time { /// @@ -31,8 +32,11 @@ namespace Orchard.Time { TimeZone = TimeZoneInfo.FindSystemTimeZoneById(siteTimeZoneId) }; } - catch(Exception e) { - Logger.Error(e, "TimeZone could not be loaded"); + catch(Exception ex) { + if (ex.IsFatal()) { + throw; + } + Logger.Error(ex, "TimeZone could not be loaded"); // if the database could not be updated in time, ignore this provider return null; diff --git a/src/Orchard/UI/Admin/Notification/NotificationManager.cs b/src/Orchard/UI/Admin/Notification/NotificationManager.cs index 327b4f1c1..d0529224c 100644 --- a/src/Orchard/UI/Admin/Notification/NotificationManager.cs +++ b/src/Orchard/UI/Admin/Notification/NotificationManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Orchard.Logging; using Orchard.UI.Notify; +using Orchard.Exceptions; namespace Orchard.UI.Admin.Notification { public class NotificationManager : INotificationManager { @@ -22,8 +23,11 @@ namespace Orchard.UI.Admin.Notification { try { return n.GetNotifications(); } - catch(Exception e) { - Logger.Error("An unhandled exception was thrown while generating a notification: " + n.GetType(), e); + catch(Exception ex) { + if (ex.IsFatal()) { + throw; + } + Logger.Error("An unhandled exception was thrown while generating a notification: " + n.GetType(), ex); return Enumerable.Empty(); } }).ToList();