-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Remove no-op SR.Format calls with single message argument #123834
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
Conversation
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR removes unnecessary SR.Format() wrapper calls when there are no format arguments, simplifying error message construction across multiple libraries. The change improves code clarity and removes no-op function calls.
Changes:
- Removed 67 instances of
SR.Format(SR.SomeMessage)calls with no format arguments, replacing them with directSR.SomeMessagereferences - Changes span 10 files across 6 different libraries/components
- All changes are mechanical refactorings that preserve exact behavior
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.cs |
Removed 4 no-op SR.Format calls in exception message handling |
src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.Serialization.cs |
Removed 3 no-op SR.Format calls in serialization exception handling |
src/libraries/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseHeaderValue.cs |
Removed 4 identical no-op SR.Format calls in header value parsing methods |
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/SchemaImporter.cs |
Removed 32 no-op SR.Format calls in schema import error handling |
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ExtensionDataReader.cs |
Removed 1 no-op SR.Format call in deserialization error handling |
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DataContractSet.cs |
Removed 2 no-op SR.Format calls in validation error handling |
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHelpers.cs |
Removed 1 no-op SR.Format call in number parsing error handling |
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Read.cs |
Removed 2 no-op SR.Format calls in TAR header parsing errors |
src/libraries/System.Formats.Tar/tests/TarEntry/GnuTarEntry.Tests.cs |
Removed 1 no-op SR.Format call in test code |
src/libraries/System.Data.OleDb/src/OleDb_Util.cs |
Removed 16 no-op SR.Format calls in OleDb exception factory methods |
src/coreclr/System.Private.CoreLib/src/System/GC.CoreCLR.cs |
Removed 2 no-op SR.Format calls in GC NoGCRegion error handling |
src/coreclr/nativeaot/System.Private.CoreLib/src/System/GC.NativeAot.cs |
Removed 2 no-op SR.Format calls in GC NoGCRegion error handling (NativeAOT variant) |
|
Tagging subscribers to this area: @dotnet/area-meta |
|
@copilot Could you please check that the error messages touched in this PR do not contain formatting sequences like |
…ns {0} placeholder
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Verified all 66 touched error messages for formatting sequences. Found one issue: All other messages were confirmed to have no format placeholders:
|
|
@copilot is that code path with the {0} in the message reachable? Do we have any tests hitting it? Such a call will typically throw an exception due to having a hole for an argument without one to fill it. |
The code path is reachable when importing an XSD complex type with a content restriction that doesn't extend You're correct that Looking at the resource strings, the Should I fix this by removing the |
|
@copilot Remove the {0} from the resource string |
… wrapper Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Done in 21482ad9. Removed the |
Description
SR.Format(SR.SomeMessage)with no format arguments is a no-op. This PR removes the unnecessary wrapper, replacing it with justSR.SomeMessage.All touched resource strings were verified to not contain format placeholders like
{0}. One resource string (ComplexTypeRestrictionNotSupported) was found to have a redundant{0}placeholder that was never being filled - this was a pre-existing bug that would throwFormatExceptionif reached. The{0}was removed from the resource string and the message simplified to "Complex type restriction is not supported."Files changed
OleDb_Util.cs(16)CoseHeaderValue.cs(4)GC.CoreCLR.cs,GC.NativeAot.cs(4)DataContractSet.cs,ExtensionDataReader.cs,SchemaImporter.cs,Strings.resx(32)ThrowHelper.cs,ThrowHelper.Serialization.cs(7)TarHelpers.cs,TarHeader.Read.cs,GnuTarEntry.Tests.cs(4)Example
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.