You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In 1.21, a JSONHandler configured with a ReplaceAttr function that deletes all attributes can output empty groups. Handlers are supposed to drop empty groups.
This is hard to fix because we can't know that the group is going to be empty until after we call ReplaceAttr on all its members. That suggests that any fix is going to be expensive: we either have to compute the replaced attrs and store them somewhere to count them, or we have to write the group elements somewhere other than the main buffer, then copy that into the main buffer if non-empty. Another idea would be to write the group name and brace into the buffer as usual, but then if it turns out the group is empty, back up and erase what we wrote.
The text was updated successfully, but these errors were encountered:
jba
added
the
NeedsFix
The path to resolution is known, but the work has not been done.
label
Sep 7, 2023
In the v2 JSON experiment, we're aiming to change the definition of omitempty to elide a Go struct field if it marshals as a JSON null or empty JSON string, object, or array. That bit of detail doesn't help you since these are dynamically generated.
In 1.21, a JSONHandler configured with a ReplaceAttr function that deletes all attributes can output empty groups. Handlers are supposed to drop empty groups.
Case 1: https://go.dev/play/p/323LJrdFALG
slog.Info("hello", slog.Group("g", "a", 1)
outputs{"g":{}}
.Case 2: https://go.dev/play/p/RnacoygwUE9
logger.WithGroup("g").Info("hello", "a", 1)
produces the same output.This is hard to fix because we can't know that the group is going to be empty until after we call ReplaceAttr on all its members. That suggests that any fix is going to be expensive: we either have to compute the replaced attrs and store them somewhere to count them, or we have to write the group elements somewhere other than the main buffer, then copy that into the main buffer if non-empty. Another idea would be to write the group name and brace into the buffer as usual, but then if it turns out the group is empty, back up and erase what we wrote.
The text was updated successfully, but these errors were encountered: