Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use corresponding exception message, if null passed #90505

Merged
merged 8 commits into from
Jan 18, 2024

Conversation

OwnageIsMagic
Copy link
Contributor

@OwnageIsMagic OwnageIsMagic commented Aug 14, 2023

Closes #89783

Notes:
Some new code already using pattern like this.

: base(message ?? SR.CborContentException_DefaultMessage)


src/libraries/System.Private.CoreLib/src/System/ArgumentException.cs
src/libraries/System.Private.CoreLib/src/System/BadImageFormatException.cs
src/libraries/System.Private.CoreLib/src/System/IO/FileLoadException.cs
src/libraries/System.Private.CoreLib/src/System/IO/FileNotFoundException.cs
src/libraries/System.Private.CoreLib/src/System/TypeLoadException.cs

override string Message via SetMessageField(), can't find where it defined.

public override string Message
{
get
{
SetMessageField();
return _message!;
}
}


Missing custom message
In CoreLib
src/libraries/System.Private.CoreLib/src/System/InvalidTimeZoneException.cs
src/libraries/System.Private.CoreLib/src/System/TimeZoneNotFoundException.cs
src/libraries/System.Private.CoreLib/src/System/ComponentModel/Win32Exception.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Contracts/ContractException.cs
src/libraries/System.Private.CoreLib/src/System/Reflection/ReflectionTypeLoadException.cs
src/libraries/System.Private.CoreLib/src/System/Reflection/TargetException.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/SEHException.cs
src/libraries/System.Private.CoreLib/src/System/Threading/LockRecursionException.cs
src/libraries/System.Private.CoreLib/src/System/Threading/ThreadAbortException.cs

Others
src/libraries/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssApiException.cs
src/libraries/Common/src/Interop/Windows/BCrypt/Interop.CreateCryptographicException.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.RaiseFailFastException.cs
src/libraries/Common/src/System/Net/InternalException.cs
src/libraries/Common/src/System/Net/Http/aspnetcore/Http2/Hpack/HPackDecodingException.cs
src/libraries/Common/src/System/Net/Http/aspnetcore/Http2/Hpack/HPackEncodingException.cs
src/libraries/Common/src/System/Net/Http/aspnetcore/Http2/Hpack/HuffmanDecodingException.cs
src/libraries/Common/src/System/Net/Http/aspnetcore/Http3/QPack/QPackDecodingException.cs
src/libraries/Common/src/System/Net/Http/aspnetcore/Http3/QPack/QPackEncodingException.cs
src/libraries/Common/src/System/Net/NetworkInformation/NetworkInformationException.cs
src/libraries/Common/src/System/Security/Cryptography/X509IterationCountExceededException.cs
src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/RuntimeBinderException.cs
src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/RuntimeBinderInternalCompilerException.cs
src/libraries/Microsoft.Extensions.Options/src/OptionsValidationException.cs
src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/ValidationException.cs
src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ChangeRejectedException.cs
src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/CompositionContractMismatchException.cs
src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/CompositionException.cs
src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ImportCardinalityMismatchException.cs
src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/ComposablePartException.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/InvalidAsynchronousStateException.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/InvalidEnumArgumentException.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/LicenseException.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/WarningException.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/CheckoutException.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationErrorsException.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationException.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SettingsPropertyIsReadOnlyException.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SettingsPropertyNotFoundException.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SettingsPropertyWrongTypeException.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/Provider/ProviderException.cs
src/libraries/System.Data.Common/src/System/Data/StrongTypingException.cs
src/libraries/System.Data.Common/src/System/Data/Common/DbException.cs
src/libraries/System.Data.Common/src/System/Data/Filter/FilterException.cs
src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcException.cs
src/libraries/System.Data.OleDb/src/OleDbException.cs
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/EventLogException.cs
src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesCOMException.cs
src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapException.cs
src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/CborContentException.cs
src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/ZLibException.cs
src/libraries/System.IO.FileSystem.Watcher/src/System/IO/InternalBufferOverflowException.cs
src/libraries/System.Management/src/System/Management/ManagementException.cs
src/libraries/System.Net.Http/src/System/Net/Http/HttpIOException.cs
src/libraries/System.Net.Http/src/System/Net/Http/HttpProtocolException.cs
src/libraries/System.Net.Http/src/System/Net/Http/HttpRequestException.cs
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocksException.cs
src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpException.cs
src/libraries/System.Net.HttpListener/src/System/Net/HttpListenerException.cs
src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpException.cs
src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpFailedRecipientException.cs
src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpFailedRecipientsException.cs
src/libraries/System.Net.Ping/src/System/Net/NetworkInformation/PingException.cs
src/libraries/System.Net.Primitives/src/System/Net/CookieException.cs
src/libraries/System.Net.Primitives/src/System/Net/SocketException.cs
src/libraries/System.Net.Quic/src/System/Net/Quic/QuicException.cs
src/libraries/System.Net.Requests/src/System/Net/ProtocolViolationException.cs
src/libraries/System.Net.Requests/src/System/Net/WebException.cs
src/libraries/System.Net.Security/src/System/Security/Authentication/AuthenticationException.cs
src/libraries/System.Private.Uri/src/System/UriFormatException.cs
src/libraries/System.Private.Xml/src/System/Xml/XmlException.cs
src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaException.cs
src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaValidationException.cs
src/libraries/System.Private.Xml/src/System/Xml/Schema/Inference/XmlSchemaInferenceException.cs
src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathCompileException.cs
src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/ImageFormatLimitationException.cs
src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/UnreachableException.cs
src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/UnreachableException.cs
src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/UnreachableException.cs
src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/UnreachableException.cs
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSException.cs
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Exception.cs
src/libraries/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/InvalidDataContractException.cs
src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CryptoSignedXmlRecursionException.cs
src/libraries/System.Security.Permissions/src/System/Security/HostProtectionException.cs
src/libraries/System.Security.Permissions/src/System/Security/XmlSyntaxException.cs
src/libraries/System.Security.Permissions/src/System/Security/Policy/PolicyException.cs
src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/TimeoutException.cs
src/libraries/System.Speech/src/Internal/Synthesis/AudioException.cs
src/libraries/System.Text.Json/src/System/Text/Json/JsonException.cs
src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderException.cs
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexParseException.cs

@stephentoub

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Aug 14, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Aug 14, 2023
@OwnageIsMagic

This comment was marked as resolved.

@OwnageIsMagic
Copy link
Contributor Author

Do I read correctly that only those 4 test failing ConfigurationErrorsExceptionTest.Constructor1 and DBConcurrencyExceptionTest.Constructor{2,3,4}?

@vcsjones
Copy link
Member

Do I read correctly that only those 4 test failing ConfigurationErrorsExceptionTest.Constructor1 and DBConcurrencyExceptionTest.Constructor{2,3,4}?

As of the latest run there appear to be a number of other failure from other CI legs as well, like MonoTests.System.Configuration.ConfigurationErrorsExceptionTest.Constructor1

Assert.Matches() Failure:
Regex: [\p{Pi}\p{Po}]System.Configuration.ConfigurationErrorsException[\p{Pf}\p{Po}]
Value: System error.

@OwnageIsMagic
Copy link
Contributor Author

@stephentoub I had some thoughts on this: I think this should be reverted for some types that are well-known base types (mainly SystemException, ApplicationException, IOException).
"Exception of type 'SomeSpecificException' was thrown." looks more preferable than unintelligible "System error." if user logs only Message property without ToString().

@marek-safar marek-safar added area-System.Runtime and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Sep 18, 2023
@ghost
Copy link

ghost commented Sep 18, 2023

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

Issue Details

Closes #89783

Notes:
Some new code already using pattern like this.

: base(message ?? SR.CborContentException_DefaultMessage)


src/libraries/System.Private.CoreLib/src/System/ArgumentException.cs
src/libraries/System.Private.CoreLib/src/System/BadImageFormatException.cs
src/libraries/System.Private.CoreLib/src/System/IO/FileLoadException.cs
src/libraries/System.Private.CoreLib/src/System/IO/FileNotFoundException.cs
src/libraries/System.Private.CoreLib/src/System/TypeLoadException.cs

override string Message via SetMessageField(), can't find where it defined.

public override string Message
{
get
{
SetMessageField();
return _message!;
}
}


Missing custom message
In CoreLib
src/libraries/System.Private.CoreLib/src/System/InvalidTimeZoneException.cs
src/libraries/System.Private.CoreLib/src/System/TimeZoneNotFoundException.cs
src/libraries/System.Private.CoreLib/src/System/ComponentModel/Win32Exception.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Contracts/ContractException.cs
src/libraries/System.Private.CoreLib/src/System/Reflection/ReflectionTypeLoadException.cs
src/libraries/System.Private.CoreLib/src/System/Reflection/TargetException.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/SEHException.cs
src/libraries/System.Private.CoreLib/src/System/Threading/LockRecursionException.cs
src/libraries/System.Private.CoreLib/src/System/Threading/ThreadAbortException.cs

Others
src/libraries/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssApiException.cs
src/libraries/Common/src/Interop/Windows/BCrypt/Interop.CreateCryptographicException.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.RaiseFailFastException.cs
src/libraries/Common/src/System/Net/InternalException.cs
src/libraries/Common/src/System/Net/Http/aspnetcore/Http2/Hpack/HPackDecodingException.cs
src/libraries/Common/src/System/Net/Http/aspnetcore/Http2/Hpack/HPackEncodingException.cs
src/libraries/Common/src/System/Net/Http/aspnetcore/Http2/Hpack/HuffmanDecodingException.cs
src/libraries/Common/src/System/Net/Http/aspnetcore/Http3/QPack/QPackDecodingException.cs
src/libraries/Common/src/System/Net/Http/aspnetcore/Http3/QPack/QPackEncodingException.cs
src/libraries/Common/src/System/Net/NetworkInformation/NetworkInformationException.cs
src/libraries/Common/src/System/Security/Cryptography/X509IterationCountExceededException.cs
src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/RuntimeBinderException.cs
src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/RuntimeBinderInternalCompilerException.cs
src/libraries/Microsoft.Extensions.Options/src/OptionsValidationException.cs
src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/ValidationException.cs
src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ChangeRejectedException.cs
src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/CompositionContractMismatchException.cs
src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/CompositionException.cs
src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ImportCardinalityMismatchException.cs
src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/ComposablePartException.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/InvalidAsynchronousStateException.cs
src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/InvalidEnumArgumentException.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/LicenseException.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/WarningException.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/CheckoutException.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationErrorsException.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationException.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SettingsPropertyIsReadOnlyException.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SettingsPropertyNotFoundException.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SettingsPropertyWrongTypeException.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/Provider/ProviderException.cs
src/libraries/System.Data.Common/src/System/Data/StrongTypingException.cs
src/libraries/System.Data.Common/src/System/Data/Common/DbException.cs
src/libraries/System.Data.Common/src/System/Data/Filter/FilterException.cs
src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcException.cs
src/libraries/System.Data.OleDb/src/OleDbException.cs
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/EventLogException.cs
src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesCOMException.cs
src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapException.cs
src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/CborContentException.cs
src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/ZLibException.cs
src/libraries/System.IO.FileSystem.Watcher/src/System/IO/InternalBufferOverflowException.cs
src/libraries/System.Management/src/System/Management/ManagementException.cs
src/libraries/System.Net.Http/src/System/Net/Http/HttpIOException.cs
src/libraries/System.Net.Http/src/System/Net/Http/HttpProtocolException.cs
src/libraries/System.Net.Http/src/System/Net/Http/HttpRequestException.cs
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocksException.cs
src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpException.cs
src/libraries/System.Net.HttpListener/src/System/Net/HttpListenerException.cs
src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpException.cs
src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpFailedRecipientException.cs
src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpFailedRecipientsException.cs
src/libraries/System.Net.Ping/src/System/Net/NetworkInformation/PingException.cs
src/libraries/System.Net.Primitives/src/System/Net/CookieException.cs
src/libraries/System.Net.Primitives/src/System/Net/SocketException.cs
src/libraries/System.Net.Quic/src/System/Net/Quic/QuicException.cs
src/libraries/System.Net.Requests/src/System/Net/ProtocolViolationException.cs
src/libraries/System.Net.Requests/src/System/Net/WebException.cs
src/libraries/System.Net.Security/src/System/Security/Authentication/AuthenticationException.cs
src/libraries/System.Private.Uri/src/System/UriFormatException.cs
src/libraries/System.Private.Xml/src/System/Xml/XmlException.cs
src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaException.cs
src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaValidationException.cs
src/libraries/System.Private.Xml/src/System/Xml/Schema/Inference/XmlSchemaInferenceException.cs
src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathCompileException.cs
src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/ImageFormatLimitationException.cs
src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/UnreachableException.cs
src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/UnreachableException.cs
src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/UnreachableException.cs
src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/UnreachableException.cs
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSException.cs
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Exception.cs
src/libraries/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/InvalidDataContractException.cs
src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CryptoSignedXmlRecursionException.cs
src/libraries/System.Security.Permissions/src/System/Security/HostProtectionException.cs
src/libraries/System.Security.Permissions/src/System/Security/XmlSyntaxException.cs
src/libraries/System.Security.Permissions/src/System/Security/Policy/PolicyException.cs
src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/TimeoutException.cs
src/libraries/System.Speech/src/Internal/Synthesis/AudioException.cs
src/libraries/System.Text.Json/src/System/Text/Json/JsonException.cs
src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderException.cs
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexParseException.cs

@stephentoub

Author: OwnageIsMagic
Assignees: -
Labels:

area-System.Runtime, community-contribution, needs-area-label

Milestone: -

Copy link
Member

@jozkee jozkee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @OwnageIsMagic. I'm curious how did you find all the exceptions in src/libraries?

"Exception of type 'SomeSpecificException' was thrown." looks more preferable than unintelligible "System error." if user logs only Message property without ToString().

I actually like more the consistency between the parameterless ctor and the other ones.

@OwnageIsMagic
Copy link
Contributor Author

OwnageIsMagic commented Oct 14, 2023

@jozkee some .Net conventions + shell hackery and then manual diff review.

$files = ls -Filter *Exception.cs -Recurse -File |% {[string]$_}

foreach ($f in $files) {
 $c=gc $f -Raw
 if ($c -cmatch '(?:base)\((SR\.(?!Format\(|GetString)[A-Za-z0-9_]+)') {
  if ($Matches.Count -gt 2) { echo 'Count' $f $Matches }
  Set-Content -LiteralPath $f -Value ($c -creplace 'base\(message' , "base(message ?? $($Matches[1])") -NoNewline
 }
 else { echo $f }
}

What about changing those types default message to also include specific type if GetType() != typeof(...)? Some Mono tests are failed, because they were checking content of Message. I can remove those checks, but I'm afraid that this kind of rigorous unit testing is quite widespread.


As a native English speaker, what do you think about my nametag? Do you find it inappropriate/aggressive or something like that?

@OwnageIsMagic
Copy link
Contributor Author

This PR cuts on "technical" aspects (aot size, microbenchmarks values) and brings in "aesthetics" (nice error messages in en culture, god save you from localized ones). This fits perfectly with .NET Framework culture, but I'm not sure about more rough and edgy Core. Maybe you can /cc some platform visionaries?

@jozkee
Copy link
Member

jozkee commented Oct 16, 2023

@OwnageIsMagic how does this affects MicroBenchmarks? Does it affect non-throwing scenarios?
cc @jkotas for AOT app size impact.

@jozkee

This comment was marked as off-topic.

@jkotas
Copy link
Member

jkotas commented Oct 16, 2023

cc @jkotas for AOT app size impact.

I do not see a problem with this change wrt AOT app size impact.

@OwnageIsMagic
Copy link
Contributor Author

@jozkee sorry for confusion. The impact is around 10-60 bytes per exception type (resource is no longer trimmable) per locale (Core doesn't have any beside EN, but I'm not sure about Mono, etc). For benchmarks, I was referring to exception object creation (without user msg) now most of the time will go through ResourceManager with bunch of thread local variables. Yeah, usually it's a throwing scenario.

@jozkee
Copy link
Member

jozkee commented Oct 17, 2023

usually it's a throwing scenario.

I think we usually don't worry for the perf of throwing scenarios and I think this wouldn't have a significant impact.

// \p{Pi} any kind of opening quote https://www.compart.com/en/unicode/category/Pi
// \p{Pf} any kind of closing quote https://www.compart.com/en/unicode/category/Pf
// \p{Po} any kind of punctuation character that is not a dash, bracket, quote or connector https://www.compart.com/en/unicode/category/Po
Assert.Matches(@"[\p{Pi}\p{Po}]" + Regex.Escape(typeof(ConfigurationErrorsException).FullName) + @"[\p{Pf}\p{Po}]", cee.BareMessage);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I quite impressed by people spending their free time writing exception constructor unit tests.

@OwnageIsMagic
Copy link
Contributor Author

OwnageIsMagic commented Oct 18, 2023

@jozkee there is problematic pattern with exceptions thrown by runtime (TypeLoadException, BadImageFormatException, FileNotFoundException and ArgumentException). They derive from SystemException which now always sets default message and override Exception.Message checking internal Exception._message field for null instead of passing message through base constructor.
The most problematic is class ArgumentException : SystemException. There is already a bug caused by that in Core (on Framework HResult is protected set, so it doesn't manifest itself):

var e = new ArgumentException(null);

e.HResult = 0;
Console.WriteLine(e);
// System.ArgumentException: Exception of type 'System.ArgumentException' was thrown.

e.HResult = -2147024809; // COR_E_ARGUMENT
Console.WriteLine(e); // message changed
// System.ArgumentException: Value does not fall within the expected range.

e.HResult = 0;
Console.WriteLine(e); // message didn't change back: ToString mutates state -- this is not nice
// System.ArgumentException: Value does not fall within the expected range.

Sharplab

This can be worked around by introducing internal SystemException(DummyType _) which doesn't set default message. Do you have any DummyType or I should create one?

@jkotas
Copy link
Member

jkotas commented Oct 18, 2023

If ArgumentException deals with the null message in its own way already, would it be better to omit it from this change? Same for all exceptions that follow this pattern.

@OwnageIsMagic
Copy link
Contributor Author

OwnageIsMagic commented Oct 18, 2023

Is there any reason for that SetMessageField pattern? Why we can't eagerly create message in constructor? I already suggested to omit this change for well-known base types #90505 (comment) , but it was rejected #90505 (review)

Copy link
Member

@jeffhandley jeffhandley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OwnageIsMagic From what I can tell, we're stalled on this pull request because it has failing CI legs that illustrate the behavioral changes.

To move this forward efficiently, could you review the failing tests and author a comment that summarizes where the behavioral changes are being observed, showing the previous and updated exception messages?

If we agree to those changes, then we'd need updates sent to the PR that update the affected tests.

@ghost ghost added the needs-author-action An issue or pull request that requires more info or actions from the author. label Nov 14, 2023
@OwnageIsMagic
Copy link
Contributor Author

Azure Pipelines / runtime (Build android-arm Release AllSubsets_Mono) Started 7h 6m 45s ago

Missing timeout?

@OwnageIsMagic
Copy link
Contributor Author

Is there anything I can do beside closing and reopening PR to get CI green?

@jozkee
Copy link
Member

jozkee commented Jan 8, 2024

Sorry, I was out for the holidays. I pinged @dotnet/mono-team hoping they could give a better insight on #90505 (comment). Will reopen the PR to see if we are still getting errors.

@jozkee jozkee reopened this Jan 8, 2024
@OwnageIsMagic
Copy link
Contributor Author

OwnageIsMagic commented Jan 9, 2024

@jozkee should I report issues with infrastructure? Pipeline didn't timed out for 9 days.
img.
I closed to restart on next day, but forgot about it.

Btw, all green, thanks for your magic touch.

@marek-safar
Copy link
Contributor

@jozkee the mono issue seems to be resolved now, right?

@jozkee
Copy link
Member

jozkee commented Jan 17, 2024

@marek-safar yes, it went away on its own.

@jozkee jozkee merged commit 56769fa into dotnet:main Jan 18, 2024
173 of 178 checks passed
tmds pushed a commit to tmds/runtime that referenced this pull request Jan 23, 2024
* use corresponding exception message if null passed

* fix

* review fixes

* fix tests

* do not use default message if null passed for SystemException, ApplicationException, IOException

* change COMException default message

---------

Co-authored-by: David Cantú <dacantu@microsoft.com>
@github-actions github-actions bot locked and limited conversation to collaborators Feb 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Runtime community-contribution Indicates that the PR has been added by a community member NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: ArgumentOutOfRangeException constructor with actualValue and system message
6 participants