Use value receivers for ChunkID String and MarshalJSON - #379
Merged
Conversation
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.
Owner
|
Thank you |
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ChunkID.String()was switched to a pointer receiver in #273, so only*ChunkIDimplementedfmt.Stringer. AChunkIDvalue passed to%sor%vwas rendered byfmt's byte-array fallback, printing the 32 raw bytes instead of hex. This affected error and log messages ins3.go,gcs.go,httphandler.go, andcmd/desync/info.go, plus test failure messages ins3_test.go.Switching
String()to a value receiver puts it in the method set of bothChunkIDand*ChunkID, fixing all format call sites at once. The same change toMarshalJSONremoves the addressability trap wherejson.Marshalof a non-addressableChunkIDwould emit a number array instead of a hex string.UnmarshalJSONkeeps its pointer receiver as it mutates the receiver.Also drop explicit
.String()calls infmtandlogrusarguments where theStringeris now picked up automatically; calls that produce an actual string value (path building, string-typed parameters) remain.