Repository navigation
Format the {0} placeholder in Asn1, Cbor and macOS FileSystemWatcher exception messages - #137808
Merged
Merged
Conversation
ContentException_EnumeratedValueTooBig and
Cbor_Reader_InvalidCbor_IndefiniteLengthStringContainsInvalidDataItem
both contain a {0} placeholder, but a few throw sites passed the raw
resource string, so the exception message showed a literal '{0}'.
Format them the same way the other throw sites already do.
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-formats-cbor, @bartonjs, @vcsjones |
FSW_BufferOverflow is "Too many changes at once in directory:{0}." but the
macOS rescan path passed it to IOException unformatted, so the error
raised through FileSystemWatcher.Error showed a literal "{0}". Format it
with the watched directory, as the shared CreateBufferOverflowException
helper does for the other platforms.
Contributor
|
Tagging subscribers to this area: @dotnet/area-meta |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the exception-message formatting changes, although builds and tests were not run during review.
No open issues 🎉
What changed in this PR
This PR fixes literal {0} placeholders in exception messages across ASN.1, CBOR, and macOS file-system watching. The changes use SR.Format without altering exception types or control flow.
Changes:
- Include the enum type name in both ASN.1 enumerated-value overflow messages.
- Include the unexpected major type in two CBOR indefinite-length string error paths.
- Include the watched directory in macOS buffer-overflow errors while preserving the HResult.
Builds and tests were not run during this review.
| File | Description |
|---|---|
src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs |
Formats the overflow message with the watched directory. |
src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.String.cs |
Formats invalid string-item errors with the major type. |
src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.PeekState.cs |
Formats the corresponding peek-state error with the major type. |
src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.Enumerated.cs |
Formats signed and unsigned overflow errors with the enum type name. |
Review effort: Balanced
bartonjs
approved these changes
Nov 18, 2026
jkotas
approved these changes
Nov 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three resources in these libraries have a
{0}placeholder, but some throw sites pass the raw resource string instead of formatting it, so the exception message contains a literal{0}:ContentException_EnumeratedValueTooBig=The encoded enumerated value is larger than the value size of the '{0}' enum.— both throw sites inAsnDecoder.ReadEnumeratedValue(signed and unsigned backing types) passed it unformatted, e.g. reading0A020102as a byte-backed enum.Cbor_Reader_InvalidCbor_IndefiniteLengthStringContainsInvalidDataItem=Indefinite-length CBOR string nests an invalid data item of major type {0}.—CborReader.csalready formats it with(int)nextByte.MajorType, but the throw sites inCborReader.PeekState.csandCborReader.String.cs(ReadNextInitialByte) did not.FSW_BufferOverflow=Too many changes at once in directory:{0}.— the macOS rescan path inFileSystemWatcher.OSX.cspassed it toIOExceptionunformatted, while the sharedCreateBufferOverflowExceptionhelper used on the other platforms formats it with the directory. Now formatted with_fullDirectory(exception type and HResult unchanged).This change formats them the same way the neighbouring throw sites already do (
enumType.FullName,(int)...MajorType, the watched directory). No behaviour change other than the message text.Same scan, left out of this PR (different areas, and they need an owner's call on the right message):
System.ComponentModel.TypeConverterTypeDescriptor.cs(ComNativeDescriptionProvider.GetTypeDescriptor):SR.Format(SR.ConvertToException, nameof(objectType), instance.GetType())— the resource has{2}, so this throwsFormatExceptioninstead of the intendedArgumentException(obsolete COM handler path).System.Private.CoreLibEventSource.cs(~3665):new WarningException(SR.EventSource_EventNameDoesNotEqualTaskPlusOpcode)—{0}/{1}unformatted.System.ComponentModel.CompositionExceptionBuilder.cs(~55) andSystem.Composition.ConventionPartConventionBuilder.cs(~343):new ArgumentException(SR.ArgumentException_EmptyString)—'{0}'unformatted.Found by checking
SR.Xthrow sites against the placeholder count of the resource in each library'sStrings.resx. Not built locally; relying on CI.Note
This PR (change and description) was prepared with AI assistance (Claude).