Skip to content

Document that setting attributes on a collection value is a programmer error - #504

Merged
kukushechkin merged 1 commit into
apple:mainfrom
lenamonj:sl002
Sep 4, 2026
Merged

kukushechkin merged 1 commit into
apple:mainfrom
lenamonj:sl002

Conversation

@lenamonj

@lenamonj lenamonj commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

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.

@kukushechkin

Copy link
Copy Markdown
Contributor

Thanks for this. I think setting attributes for an array or a dictionary should be a visible programmer error. We cannot express this as an API limitation unfortunately.

What is the expected behavior for that intermediate log handler, would it rather propagate attributes inside containers?

@lenamonj

lenamonj commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Fair enough, a programmer error works for me. My real complaint is that debug traps while release silently drops it, and the doc says “no-op”. If you want the assertion, I’ll rework this to keep it and fix the doc to say so.
For the intermediate handler, I’d only set attributes on leaf values, recursing into containers, rather than on the container itself. Happy to go either way.

@lenamonj lenamonj changed the title Make the attributes setter a no-op on collection values, as documented Document that setting attributes on a collection value is a programmer error Sep 4, 2026
@lenamonj

lenamonj commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Reworked as doc-only: the assertion stays, the comment now calls it a programmer error and points at setting attributes on the leaf values instead.

@kukushechkin
kukushechkin enabled auto-merge (squash) September 4, 2026 08:53
@czechboy0 czechboy0 added the semver/none No version bump required. label Sep 4, 2026
@kukushechkin
kukushechkin merged commit c5ece24 into apple:main Sep 4, 2026
53 of 56 checks passed
@lenamonj
lenamonj deleted the sl002 branch September 5, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver/none No version bump required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants