Skip to content

Commit da15459

Browse files
authored
Fix early file close in jwt cli (#472)
1 parent b625028 commit da15459

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

cmd/jwt/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package main
99

1010
import (
1111
"encoding/json"
12+
"errors"
1213
"flag"
1314
"fmt"
1415
"io"
@@ -74,7 +75,7 @@ func start() error {
7475
}
7576

7677
// Helper func: Read input from specified file or stdin
77-
func loadData(p string) ([]byte, error) {
78+
func loadData(p string) (_ []byte, retErr error) {
7879
if p == "" {
7980
return nil, fmt.Errorf("no path specified")
8081
}
@@ -91,9 +92,9 @@ func loadData(p string) ([]byte, error) {
9192
return nil, err
9293
}
9394
rdr = f
94-
if err := f.Close(); err != nil {
95-
return nil, err
96-
}
95+
defer func() {
96+
retErr = errors.Join(retErr, f.Close())
97+
}()
9798
}
9899
return io.ReadAll(rdr)
99100
}

0 commit comments

Comments
 (0)