zeroshade commented on code in PR #1871:
URL: https://github.com/apache/iceberg-go/pull/1871#discussion_r3855268139


##########
table/snapshots.go:
##########
@@ -272,9 +272,27 @@ type Snapshot struct {
 func (s *Snapshot) UnmarshalJSON(data []byte) error {
        type Alias Snapshot
        var next Alias
-       if err := json.Unmarshal(data, &next); err != nil {
+       // snapshot-id and timestamp-ms are required by the spec for every 
format
+       // version. Decode them through pointers so an absent or null field 
stays
+       // distinguishable from an explicit zero, which would otherwise be 
accepted
+       // as a valid identity or as the Unix epoch.
+       aux := struct {
+               SnapshotID  *int64 `json:"snapshot-id"`
+               TimestampMs *int64 `json:"timestamp-ms"`
+               *Alias
+       }{Alias: &next}
+
+       if err := json.Unmarshal(data, &aux); err != nil {
                return err
        }
+       if aux.SnapshotID == nil {
+               return fmt.Errorf("%w: snapshot-id is absent or null", 
ErrInvalidMetadata)

Review Comment:
   `ParseMetadataBytes` wraps every `json.Unmarshal` failure with 
`ErrInvalidMetadata`, so wrapping the same sentinel here produces duplicated 
public text: `invalid metadata: invalid metadata: snapshot-id is absent or 
null`. Please avoid the outer wrap when the nested error already satisfies 
`errors.Is(err, ErrInvalidMetadata)` (and add an exact error-text assertion so 
this does not regress).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to