From c5ece247864fe3d206c8c68bb68b3413447c61ae Mon Sep 17 00:00:00 2001 From: Jeff Lenamon <85593689+lenamonj@users.noreply.github.com> Date: Fri, 4 Sep 2026 05:08:57 -0400 Subject: [PATCH] Document that setting attributes on a collection value is a programmer error (#504) ### Motivation: `Logger.MetadataValue.attributes` documents the setter as a no-op for `.dictionary` and `.array`, but it calls `assertionFailure` there. Debug builds trap, release builds do the documented no-op. ### Modifications: Doc comment only. The assertion stays; the comment now says setting attributes on a collection value is a programmer error, that debug builds assert and release builds leave the value unchanged, and to set attributes on the leaf values instead. ### Result: The documentation matches the code. No behaviour change. Found by an automated audit loop (Claude); patch and description reviewed by me. --- Sources/Logging/Logger+Attributes.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/Logging/Logger+Attributes.swift b/Sources/Logging/Logger+Attributes.swift index ff5646a..41f5c57 100644 --- a/Sources/Logging/Logger+Attributes.swift +++ b/Sources/Logging/Logger+Attributes.swift @@ -262,7 +262,9 @@ extension Logger.MetadataValue { /// /// **Setting:** Replaces the value with `.stringConvertible(AttributedStringCarrier(...))` /// carrying the given attributes. For `.string` and `.stringConvertible` cases the string - /// representation is preserved. For `.dictionary` and `.array` cases the setter is a no-op. + /// representation is preserved. Setting attributes on a `.dictionary` or `.array` value is a + /// programmer error: it triggers an assertion in debug builds and leaves the value unchanged in + /// release builds. Set attributes on the leaf values instead. /// /// Only handlers that inspect attributes pay the cost of the getter check. @inlinable