Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#71: Fix deferred error checks #72

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion files.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ func FilePutContents(fileName, data string, flags ...interface{}) (int, error) {
}

f, err := os.OpenFile(fileName, v|os.O_WRONLY, 0644)
defer f.Close()
defer func(f *os.File) {
err = f.Close()
if err != nil {
fmt.Println(err)
}
}(f)

if err != nil {
return -1, err
Expand Down
23 changes: 20 additions & 3 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
)
Expand All @@ -27,7 +28,12 @@
return "", err
}

defer resp.Body.Close()
defer func(body io.ReadCloser) {
err = body.Close()
if err != nil {
fmt.Println(err)

Check warning on line 34 in request.go

View check run for this annotation

Codecov / codecov/patch

request.go#L34

Added line #L34 was not covered by tests
}
}(resp.Body)

content, cErr := io.ReadAll(resp.Body)

Expand Down Expand Up @@ -56,15 +62,26 @@
return false
}

defer file.Close()
defer func(file multipart.File) {
err = file.Close()
if err != nil {
fmt.Println(err)

Check warning on line 68 in request.go

View check run for this annotation

Codecov / codecov/patch

request.go#L65-L68

Added lines #L65 - L68 were not covered by tests
}
}(file)

f, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
fmt.Println(err)
return false
}

defer f.Close()
defer func(f *os.File) {
err = f.Close()
if err != nil {
fmt.Println(err)

Check warning on line 81 in request.go

View check run for this annotation

Codecov / codecov/patch

request.go#L78-L81

Added lines #L78 - L81 were not covered by tests
}
}(f)

_, err = io.Copy(f, file)
if err != nil {
fmt.Println(err)
Expand Down
Loading