From 15ece8e1b587edd35af4c092e30e8666b2d9e66f Mon Sep 17 00:00:00 2001 From: Dan Moseley Date: Wed, 19 Jun 2019 01:28:30 -0700 Subject: [PATCH] Exception format cleanup subset (#25185) * Change ArgumentException message to one line * Disable 2 tests * Remove duplication in AggregateException.ToString() * Inner exceptions on new lines * Caps letter * Typo --- src/System.Private.CoreLib/Resources/Strings.resx | 2 +- src/System.Private.CoreLib/shared/System/AggregateException.cs | 6 ++++-- src/System.Private.CoreLib/shared/System/ArgumentException.cs | 7 +++---- .../shared/System/BadImageFormatException.cs | 2 +- src/System.Private.CoreLib/shared/System/Exception.cs | 4 +++- src/System.Private.CoreLib/shared/System/IO/FileLoadException.cs | 2 +- .../shared/System/IO/FileNotFoundException.cs | 2 +- .../shared/System/Runtime/InteropServices/COMException.cs | 4 ++-- .../shared/System/Runtime/InteropServices/ExternalException.cs | 2 +- tests/CoreFX/CoreFX.issues.rsp | 4 ++++ 10 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/System.Private.CoreLib/Resources/Strings.resx b/src/System.Private.CoreLib/Resources/Strings.resx index 48cbbcf..3bd8d5a 100644 --- a/src/System.Private.CoreLib/Resources/Strings.resx +++ b/src/System.Private.CoreLib/Resources/Strings.resx @@ -668,7 +668,7 @@ Insufficient memory to continue the execution of the program. - Parameter name: {0} + (Parameter '{0}') Must specify one or more parameters. diff --git a/src/System.Private.CoreLib/shared/System/AggregateException.cs b/src/System.Private.CoreLib/shared/System/AggregateException.cs index 08cda7c..d19a70e 100644 --- a/src/System.Private.CoreLib/shared/System/AggregateException.cs +++ b/src/System.Private.CoreLib/shared/System/AggregateException.cs @@ -451,8 +451,10 @@ namespace System for (int i = 0; i < m_innerExceptions.Count; i++) { - text.AppendLine(); - text.Append("---> "); + if (m_innerExceptions[i] == InnerException) + continue; // Already logged in base.ToString() + + text.Append(Environment.NewLine).Append(InnerExceptionPrefix); text.AppendFormat(CultureInfo.InvariantCulture, SR.AggregateException_InnerException, i); text.Append(m_innerExceptions[i].ToString()); text.Append("<---"); diff --git a/src/System.Private.CoreLib/shared/System/ArgumentException.cs b/src/System.Private.CoreLib/shared/System/ArgumentException.cs index 6e38c7b..a803b1a 100644 --- a/src/System.Private.CoreLib/shared/System/ArgumentException.cs +++ b/src/System.Private.CoreLib/shared/System/ArgumentException.cs @@ -81,11 +81,10 @@ namespace System string s = base.Message; if (!string.IsNullOrEmpty(_paramName)) { - string resourceString = SR.Format(SR.Arg_ParamName_Name, _paramName); - return s + Environment.NewLine + resourceString; + s += " " + SR.Format(SR.Arg_ParamName_Name, _paramName); } - else - return s; + + return s; } } diff --git a/src/System.Private.CoreLib/shared/System/BadImageFormatException.cs b/src/System.Private.CoreLib/shared/System/BadImageFormatException.cs index 23aa564..913e2b9 100644 --- a/src/System.Private.CoreLib/shared/System/BadImageFormatException.cs +++ b/src/System.Private.CoreLib/shared/System/BadImageFormatException.cs @@ -104,7 +104,7 @@ namespace System s += Environment.NewLine + SR.Format(SR.IO_FileName_Name, _fileName); if (InnerException != null) - s = s + " ---> " + InnerException.ToString(); + s = s + InnerExceptionPrefix + InnerException.ToString(); if (StackTrace != null) s += Environment.NewLine + StackTrace; diff --git a/src/System.Private.CoreLib/shared/System/Exception.cs b/src/System.Private.CoreLib/shared/System/Exception.cs index 2f07ca2..30b808d 100644 --- a/src/System.Private.CoreLib/shared/System/Exception.cs +++ b/src/System.Private.CoreLib/shared/System/Exception.cs @@ -11,6 +11,8 @@ namespace System [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public partial class Exception : ISerializable { + internal protected const string InnerExceptionPrefix = " ---> "; + public Exception() { _HResult = HResults.COR_E_EXCEPTION; @@ -151,7 +153,7 @@ namespace System if (_innerException != null) { - s = s + " ---> " + _innerException.ToString() + Environment.NewLine + + s = s + Environment.NewLine + InnerExceptionPrefix + _innerException.ToString() + Environment.NewLine + " " + SR.Exception_EndOfInnerExceptionStack; } diff --git a/src/System.Private.CoreLib/shared/System/IO/FileLoadException.cs b/src/System.Private.CoreLib/shared/System/IO/FileLoadException.cs index 729d480..30f0278 100644 --- a/src/System.Private.CoreLib/shared/System/IO/FileLoadException.cs +++ b/src/System.Private.CoreLib/shared/System/IO/FileLoadException.cs @@ -64,7 +64,7 @@ namespace System.IO s += Environment.NewLine + SR.Format(SR.IO_FileName_Name, FileName); if (InnerException != null) - s = s + " ---> " + InnerException.ToString(); + s = s + Environment.NewLine + InnerExceptionPrefix + InnerException.ToString(); if (StackTrace != null) s += Environment.NewLine + StackTrace; diff --git a/src/System.Private.CoreLib/shared/System/IO/FileNotFoundException.cs b/src/System.Private.CoreLib/shared/System/IO/FileNotFoundException.cs index 0ce1c74..334325b 100644 --- a/src/System.Private.CoreLib/shared/System/IO/FileNotFoundException.cs +++ b/src/System.Private.CoreLib/shared/System/IO/FileNotFoundException.cs @@ -78,7 +78,7 @@ namespace System.IO s += Environment.NewLine + SR.Format(SR.IO_FileName_Name, FileName); if (InnerException != null) - s = s + " ---> " + InnerException.ToString(); + s = s + Environment.NewLine + InnerExceptionPrefix + InnerException.ToString(); if (StackTrace != null) s += Environment.NewLine + StackTrace; diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/COMException.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/COMException.cs index 2dec6b8..1b66bb6 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/COMException.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/COMException.cs @@ -48,7 +48,7 @@ namespace System.Runtime.InteropServices public override string ToString() { StringBuilder s = new StringBuilder(); - + string className = GetType().ToString(); s.Append(className).Append(" (0x").Append(HResult.ToString("X8", CultureInfo.InvariantCulture)).Append(')'); @@ -61,7 +61,7 @@ namespace System.Runtime.InteropServices Exception? innerException = InnerException; if (innerException != null) { - s.Append(" ---> ").Append(innerException.ToString()); + s.Append(Environment.NewLine).Append(InnerExceptionPrefix).Append(innerException.ToString()); } string? stackTrace = StackTrace; diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ExternalException.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ExternalException.cs index d587d82..9028288 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ExternalException.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ExternalException.cs @@ -75,7 +75,7 @@ namespace System.Runtime.InteropServices Exception? innerException = InnerException; if (innerException != null) { - s = s + " ---> " + innerException.ToString(); + s = s + Environment.NewLine + InnerExceptionPrefix + innerException.ToString(); } if (StackTrace != null) diff --git a/tests/CoreFX/CoreFX.issues.rsp b/tests/CoreFX/CoreFX.issues.rsp index 8a35ea3..40c0fd4 100644 --- a/tests/CoreFX/CoreFX.issues.rsp +++ b/tests/CoreFX/CoreFX.issues.rsp @@ -92,6 +92,10 @@ # Assert: https://github.com/dotnet/coreclr/issues/25050 -nonamespace System.Data.Common.Tests +# requires corefx test updates +-nomethod System.Data.Tests.Common.DbConnectionStringBuilderTest.Add_Keyword_Invalid +-nomethod System.Data.Tests.Common.DbConnectionStringBuilderTest.Indexer_Keyword_Invalid + # requires corefx test updates https://github.com/dotnet/corefx/pull/38452 -nomethod System.SpanTests.ReadOnlySpanTests.ZeroLengthIndexOfAny_ManyInteger -nomethod System.SpanTests.ReadOnlySpanTests.ZeroLengthIndexOfAny_ManyString -- 2.7.4