From f83234a87fd50192d1d53d34d159d88ad49ade5f Mon Sep 17 00:00:00 2001 From: Zhi Li Date: Thu, 25 Feb 2016 15:21:18 -0800 Subject: [PATCH] fixed https://github.com/NuGet/Home/issues/2158 and https://github.com/NuGet/Home/issues/1567 --- .../Options/PackageSourcesOptionsControl.cs | 9 +++------ .../Properties/Resources.Designer.cs | 16 ++++++++++++++++ .../NuGet.Configuration/Resources.resx | 10 ++++++++-- .../NuGet.Configuration/Settings/Settings.cs | 16 ++++++++++++++-- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/NuGet.Clients/Options/PackageSourcesOptionsControl.cs b/src/NuGet.Clients/Options/PackageSourcesOptionsControl.cs index 8b7c51d3c07..0e8f04217ac 100644 --- a/src/NuGet.Clients/Options/PackageSourcesOptionsControl.cs +++ b/src/NuGet.Clients/Options/PackageSourcesOptionsControl.cs @@ -227,15 +227,12 @@ internal bool ApplyChangedSettings() _packageSourceProvider.SavePackageSources(packageSources); } } - catch (InvalidOperationException) + catch (Configuration.NuGetConfigurationException e) { - MessageHelper.ShowErrorMessage(Resources.ShowError_ConfigInvalidOperation, Resources.ErrorDialogBoxTitle); + MessageHelper.ShowErrorMessage(e.Message, Resources.ErrorDialogBoxTitle); return false; } - catch (UnauthorizedAccessException) - { - MessageHelper.ShowErrorMessage(Resources.ShowError_ConfigUnauthorizedAccess, Resources.ErrorDialogBoxTitle); - } + // find the enabled package source return true; } diff --git a/src/NuGet.Core/NuGet.Configuration/Properties/Resources.Designer.cs b/src/NuGet.Core/NuGet.Configuration/Properties/Resources.Designer.cs index 7817c8238b9..1a1b450571c 100644 --- a/src/NuGet.Core/NuGet.Configuration/Properties/Resources.Designer.cs +++ b/src/NuGet.Core/NuGet.Configuration/Properties/Resources.Designer.cs @@ -152,6 +152,22 @@ public static string ShowError_ConfigUnauthorizedAccess } } + public static string ShowError_ConfigInvalidXml + { + get + { + return GetString("ShowError_ConfigInvalidXml"); + } + } + + public static string Unknown_Config_Exception + { + get + { + return GetString("Unknown_Config_Exception"); + } + } + /// /// Unable to parse config file '{0}'. /// diff --git a/src/NuGet.Core/NuGet.Configuration/Resources.resx b/src/NuGet.Core/NuGet.Configuration/Resources.resx index b5a061bb45d..2d4c6a7710c 100644 --- a/src/NuGet.Core/NuGet.Configuration/Resources.resx +++ b/src/NuGet.Core/NuGet.Configuration/Resources.resx @@ -136,10 +136,16 @@ Parameter 'fileName' to Settings must be just a fileName and not a path - NuGet.Config is malformed, Please check NuGet.Config at '{0}'. + NuGet.Config is malformed, Please check NuGet.Config at '{0}', exception message is '{1}'. + + + NuGet.Config is invalid XML, Please check NuGet.Config at '{0}', exception message is '{1}'. - Can not access NuGet.Config, Please check NuGet.Config at '{0}'. + Can not access NuGet.Config, Please check NuGet.Config at '{0}', exception message is '{1}'. + + + Got exception From NuGet.Config, Please check NuGet.Config at '{0}', exception message is '{1}'. Hash algorithm '{0}' is unsupported. Supported algorithms include: SHA512 and SHA256. diff --git a/src/NuGet.Core/NuGet.Configuration/Settings/Settings.cs b/src/NuGet.Core/NuGet.Configuration/Settings/Settings.cs index e1c44f379f4..c1882d34e02 100644 --- a/src/NuGet.Core/NuGet.Configuration/Settings/Settings.cs +++ b/src/NuGet.Core/NuGet.Configuration/Settings/Settings.cs @@ -1068,13 +1068,25 @@ private void ExecuteSynchronizedCore(Action ioOperation) catch(InvalidOperationException e) { throw new NuGetConfigurationException( - string.Format(Resources.ShowError_ConfigInvalidOperation, fileName), e); + string.Format(Resources.ShowError_ConfigInvalidOperation, fileName, e.Message), e); } catch (UnauthorizedAccessException e) { throw new NuGetConfigurationException( - string.Format(Resources.ShowError_ConfigUnauthorizedAccess, fileName), e); + string.Format(Resources.ShowError_ConfigUnauthorizedAccess, fileName, e.Message), e); + } + + catch (XmlException e) + { + throw new NuGetConfigurationException( + string.Format(Resources.ShowError_ConfigInvalidXml, fileName, e.Message), e); + } + + catch (Exception e) + { + throw new NuGetConfigurationException( + string.Format(Resources.ShowError_ConfigInvalidXml, fileName, e.Message), e); } finally