Skip to content

Format the {0} placeholder in Asn1, Cbor and macOS FileSystemWatcher exception messages - #137808

Merged
jkotas merged 2 commits into
dotnet:mainfrom
farisbasha:fix-formats-message-placeholders
Nov 19, 2026
Merged

jkotas merged 2 commits into
dotnet:mainfrom
farisbasha:fix-formats-message-placeholders

Conversation

@farisbasha

@farisbasha farisbasha commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

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 in AsnDecoder.ReadEnumeratedValue (signed and unsigned backing types) passed it unformatted, e.g. reading 0A020102 as a byte-backed enum.
  • Cbor_Reader_InvalidCbor_IndefiniteLengthStringContainsInvalidDataItem = Indefinite-length CBOR string nests an invalid data item of major type {0}. — CborReader.cs already formats it with (int)nextByte.MajorType, but the throw sites in CborReader.PeekState.cs and CborReader.String.cs (ReadNextInitialByte) did not.
  • FSW_BufferOverflow = Too many changes at once in directory:{0}. — the macOS rescan path in FileSystemWatcher.OSX.cs passed it to IOException unformatted, while the shared CreateBufferOverflowException helper 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.TypeConverter TypeDescriptor.cs (ComNativeDescriptionProvider.GetTypeDescriptor): SR.Format(SR.ConvertToException, nameof(objectType), instance.GetType()) — the resource has {2}, so this throws FormatException instead of the intended ArgumentException (obsolete COM handler path).
  • System.Private.CoreLib EventSource.cs (~3665): new WarningException(SR.EventSource_EventNameDoesNotEqualTaskPlusOpcode) — {0}/{1} unformatted.
  • System.ComponentModel.Composition ExceptionBuilder.cs (~55) and System.Composition.Convention PartConventionBuilder.cs (~343): new ArgumentException(SR.ArgumentException_EmptyString) — '{0}' unformatted.

Found by checking SR.X throw sites against the placeholder count of the resource in each library's Strings.resx. Not built locally; relying on CI.

Note

This PR (change and description) was prepared with AI assistance (Claude).

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.
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 18, 2026
@azure-pipelines

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-formats-cbor, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

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.
@farisbasha farisbasha changed the title Format the placeholder in Asn1 and Cbor reader exception messages Format the {0} placeholder in Asn1, Cbor and macOS FileSystemWatcher exception messages Nov 18, 2026
@bartonjs
bartonjs requested a balanced review from Copilot November 18, 2026 18:44
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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

@jkotas
jkotas merged commit 5d26a50 into dotnet:main Nov 19, 2026
78 of 80 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Meta community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants