Skip to content

I/O exception reading NuGet.config does not log the original exception message #12651

Open
@jeffkl

Description

@jeffkl

NuGet Product Used

MSBuild.exe

Product Version

All

Worked before?

No response

Impact

It bothers me. A fix would be nice

Repro Steps & Context

When the code in SettingsFile attempts to perform I/O tasks, it does so in a utility method, ExecuteSynchronized. This method catches several exception types and re-throws it with a new message. The current four messages include the path to the file that was attempted to be read but does not include the original exception method.

https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Configuration/Resources.resx#L245

  <data name="ShowError_ConfigInvalidOperation" xml:space="preserve">
    <value>NuGet.Config is malformed. Path: '{0}'.</value>
  </data>
  <data name="ShowError_ConfigInvalidXml" xml:space="preserve">
    <value>NuGet.Config is not valid XML. Path: '{0}'.</value>
  </data>
  <data name="ShowError_ConfigUnauthorizedAccess" xml:space="preserve">
    <value>Failed to read NuGet.Config due to unauthorized access. Path: '{0}'.</value>
  </data>
  <data name="Unknown_Config_Exception" xml:space="preserve">
    <value>Unexpected failure reading NuGet.Config. Path: '{0}'.</value>
  </data>

The code is passing the message, the string resource just doesn't include it in the new exception.

try
{
    ioOperation();
}
catch (InvalidOperationException e)
{
    throw new NuGetConfigurationException(
        string.Format(CultureInfo.CurrentCulture, Resources.ShowError_ConfigInvalidOperation, ConfigFilePath, e.Message), e);
}

catch (UnauthorizedAccessException e)
{
    throw new NuGetConfigurationException(
        string.Format(CultureInfo.CurrentCulture, Resources.ShowError_ConfigUnauthorizedAccess, ConfigFilePath, e.Message), e);
}

catch (XmlException e)
{
    throw new NuGetConfigurationException(
        string.Format(CultureInfo.CurrentCulture, Resources.ShowError_ConfigInvalidXml, ConfigFilePath, e.Message), e);
}

catch (Exception e)
{
    throw new NuGetConfigurationException(
        string.Format(CultureInfo.CurrentCulture, Resources.Unknown_Config_Exception, ConfigFilePath, e.Message), e);
}

Verbose Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area:ErrorHandlingwarnings and errors/log messages & related error codes.Category:Quality WeekIssues that should be considered for quality weekPriority:2Issues for the current backlog.Type:Bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions