From e1fc329a75fa723f8ff938af1e180dbf963f228d Mon Sep 17 00:00:00 2001 From: Volodymyr Usarskyy Date: Sun, 29 Sep 2013 21:38:27 +0200 Subject: [PATCH] EnableFeature: added code to throw meaningful exceptions if module dependencies not found --- .../Environment/Features/FeatureManager.cs | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/Orchard/Environment/Features/FeatureManager.cs b/src/Orchard/Environment/Features/FeatureManager.cs index 993fd8f7d..0274d0880 100644 --- a/src/Orchard/Environment/Features/FeatureManager.cs +++ b/src/Orchard/Environment/Features/FeatureManager.cs @@ -138,17 +138,29 @@ namespace Orchard.Environment.Features { /// Boolean parameter indicating if the feature should enable it's dependencies if required or fail otherwise. /// An enumeration of the enabled features. private IEnumerable EnableFeature(string featureId, IDictionary availableFeatures, bool force) { - var getDisabledDependencies = - new Func, IDictionary>( - (currentFeatureId, featuresState) => { - KeyValuePair feature = featuresState.Single(featureState => featureState.Key.Id.Equals(currentFeatureId, StringComparison.OrdinalIgnoreCase)); + var getDisabledDependencies = + new Func, IDictionary>( + (currentFeatureId, featuresState) => { + KeyValuePair feature = featuresState.Single(featureState => featureState.Key.Id.Equals(currentFeatureId, StringComparison.OrdinalIgnoreCase)); - // Retrieve disabled dependencies for the current feature - return feature.Key.Dependencies - .Select(fId => featuresState.Single(featureState => featureState.Key.Id.Equals(fId, StringComparison.OrdinalIgnoreCase))) - .Where(featureState => !featureState.Value) - .ToDictionary(f => f.Key, f => f.Value); - }); + // Retrieve disabled dependencies for the current feature + return feature.Key.Dependencies + .Select(fId => { + var states = featuresState.Where(featureState => featureState.Key.Id.Equals(fId, StringComparison.OrdinalIgnoreCase)).ToList(); + + if (states.Count == 0) { + throw new ApplicationException("Failed to get state for feature " + fId); + } + + if (states.Count > 1) { + throw new ApplicationException("Found " + states.Count + " states for feature " + fId); + } + + return states[0]; + }) + .Where(featureState => !featureState.Value) + .ToDictionary(f => f.Key, f => f.Value); + }); IEnumerable featuresToEnable = GetAffectedFeatures(featureId, availableFeatures, getDisabledDependencies); if (featuresToEnable.Count() > 1 && !force) {