From ecfbb15207fe4dfb327450db38076f48a868ce4f Mon Sep 17 00:00:00 2001 From: Petr Onderka Date: Mon, 13 Jul 2026 19:22:30 +0200 Subject: [PATCH 1/2] Raise InternalBufferOverflowException for FSEvents overflow on macOS On macOS, an FSEvents buffer/rescan overflow raised a plain IOException with the unformatted SR.FSW_BufferOverflow string (so the message literally contained "{0}"). Windows and Linux both use the shared CreateBufferOverflowException helper, which produces an InternalBufferOverflowException with a properly formatted message. Use that helper on macOS too so the overflow exception type and message are consistent across platforms, while preserving the FSEvents flags in HResult for diagnostics as the previous IOException did. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: aeef6f66-c627-4a58-a4cb-6d14cf4d2649 --- .../src/System/IO/FileSystemWatcher.OSX.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs index 86294f879b39d3..3af573ca11a3b3 100644 --- a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs +++ b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs @@ -456,7 +456,9 @@ private unsafe void ProcessEvents(int numEvents, // First, we should check if this event should kick off a re-scan since we can't really rely on anything after this point if that is true if (ShouldRescanOccur(eventFlags[i])) { - watcher.OnError(new ErrorEventArgs(new IOException(SR.FSW_BufferOverflow, (int)eventFlags[i]))); + InternalBufferOverflowException exception = CreateBufferOverflowException(_fullDirectory); + exception.HResult = (int)eventFlags[i]; + watcher.OnError(new ErrorEventArgs(exception)); break; } else if (handledRenameEvents == i) From f113fa84ee50700d06165ffcd8dd67509f29fcfc Mon Sep 17 00:00:00 2001 From: Petr Onderka Date: Thu, 16 Jul 2026 17:49:04 +0200 Subject: [PATCH 2/2] Don't preserve eventFlags in exception HResult --- .../src/System/IO/FileSystemWatcher.OSX.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs index 3af573ca11a3b3..16906d0e9fee40 100644 --- a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs +++ b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs @@ -456,9 +456,7 @@ private unsafe void ProcessEvents(int numEvents, // First, we should check if this event should kick off a re-scan since we can't really rely on anything after this point if that is true if (ShouldRescanOccur(eventFlags[i])) { - InternalBufferOverflowException exception = CreateBufferOverflowException(_fullDirectory); - exception.HResult = (int)eventFlags[i]; - watcher.OnError(new ErrorEventArgs(exception)); + watcher.OnError(new ErrorEventArgs(CreateBufferOverflowException(_fullDirectory))); break; } else if (handledRenameEvents == i)