Skip to content

Use value receivers for ChunkID String and MarshalJSON - #379

Merged
folbricht merged 1 commit into
folbricht:masterfrom
matshch:chunkid-value-receiver
Aug 4, 2026
Merged

Use value receivers for ChunkID String and MarshalJSON#379
folbricht merged 1 commit into
folbricht:masterfrom
matshch:chunkid-value-receiver

Conversation

@matshch

@matshch matshch commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

ChunkID.String() was switched to a pointer receiver in #273, so only *ChunkID implemented fmt.Stringer. A ChunkID value passed to %s or %v was rendered by fmt's byte-array fallback, printing the 32 raw bytes instead of hex. This affected error and log messages in s3.go, gcs.go, httphandler.go, and cmd/desync/info.go, plus test failure messages in s3_test.go.

Switching String() to a value receiver puts it in the method set of both ChunkID and *ChunkID, fixing all format call sites at once. The same change to MarshalJSON removes the addressability trap where json.Marshal of a non-addressable ChunkID would emit a number array instead of a hex string. UnmarshalJSON keeps its pointer receiver as it mutates the receiver.

Also drop explicit .String() calls in fmt and logrus arguments where the Stringer is now picked up automatically; calls that produce an actual string value (path building, string-typed parameters) remain.

ChunkID.String() was switched to a pointer receiver in folbricht#273, so only
*ChunkID implemented fmt.Stringer. A ChunkID value passed to %s or %v
was rendered by fmt's byte-array fallback, printing the 32 raw bytes
instead of hex. This affected error and log messages in s3.go, gcs.go,
httphandler.go, and cmd/desync/info.go, plus test failure messages in
s3_test.go.

Switching String() to a value receiver puts it in the method set of
both ChunkID and *ChunkID, fixing all format call sites at once. The
same change to MarshalJSON removes the addressability trap where
json.Marshal of a non-addressable ChunkID would emit a number array
instead of a hex string. UnmarshalJSON keeps its pointer receiver as
it mutates the receiver.

Also drop explicit .String() calls in fmt and logrus arguments where
the Stringer is now picked up automatically; calls that produce an
actual string value (path building, string-typed parameters) remain.
@folbricht

Copy link
Copy Markdown
Owner

Thank you

@folbricht
folbricht merged commit 9589c5b into folbricht:master Aug 4, 2026
3 checks passed
folbricht added a commit that referenced this pull request Aug 4, 2026
ChunkID.String() and MarshalJSON() were briefly moved to pointer
receivers in #273, which meant a ChunkID value was rendered by fmt's
byte-array fallback and marshalled as an array of numbers. #379 moved
them back to value receivers but added no test, so the same regression
could slip in again unnoticed.

Cover both the formatting and the JSON encoding of a ChunkID value,
including the non-addressable map-value case that skips a
pointer-receiver MarshalJSON, plus compile-time assertions that the
value type implements fmt.Stringer and json.Marshaler.
@matshch
matshch deleted the chunkid-value-receiver branch August 4, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants