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


##########
catalog/internal/utils.go:
##########
@@ -344,7 +344,11 @@ func CreateViewMetadata(
        if err != nil {
                return "", fmt.Errorf("failed to create view metadata file: 
%w", err)
        }
-       defer out.Close()
+       defer func() {
+               if cerr := out.Close(); cerr != nil {
+                       err = errors.Join(err, fmt.Errorf("error closing 
FileWriter: %w", cerr))
+               }
+       }()

Review Comment:
   we should make a helper function that looks like:
   
   ```go
   func checkedClose(c io.Closer, err *error) {
       *err = errors.Join(*err, c.Close())
   }
   ```
   
   then all of these locations just become:
   
   ```go
   defer checkedClose(out, &err)
   ```
   
   which would make it much easier to read, remember, and reason about. 
Remember that `errors.Join` will ignore nil errors so we don't even need to do 
the `if cerr := out.Close(); cerr != nil` part



-- 
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