Fix lint errors related to not checking errors

This commit is contained in:
Eli Ribble 2026-05-02 00:37:28 +00:00
parent 7f71ff9a2e
commit 52d4c47e43
No known key found for this signature in database
7 changed files with 54 additions and 10 deletions

View file

@ -163,7 +163,10 @@ func SigninUser(r *http.Request, username string, password string) (*platform.Us
func SignoutUser(r *http.Request, user platform.User) {
sessionManager.Put(r.Context(), "user_id", "")
sessionManager.Put(r.Context(), "username", "")
sessionManager.Destroy(r.Context())
err := sessionManager.Destroy(r.Context())
if err != nil {
log.Error().Err(err).Msg("failed to destroy session for user on signout")
}
log.Info().Str("username", user.Username).Int("user_id", (user.ID)).Msg("Ended user session")
}

View file

@ -76,7 +76,12 @@ func doMigrations(connection_string string) error {
if err != nil {
return fmt.Errorf("Failed to open database connection: %w", err)
}
defer db.Close()
defer func() {
err := db.Close()
if err != nil {
log.Error().Err(err).Msg("failed to close database connection")
}
}()
row := db.QueryRowContext(context.Background(), "SELECT version()")
var val string
if err := row.Scan(&val); err != nil {
@ -157,7 +162,12 @@ func needsMigrations(connection_string string) (*bool, error) {
if err != nil {
return nil, fmt.Errorf("Failed to open database connection: %w", err)
}
defer db.Close()
defer func() {
err := db.Close()
if err != nil {
log.Error().Err(err).Msg("failed to close database connection")
}
}()
row := db.QueryRowContext(context.Background(), "SELECT version()")
var val string
if err := row.Scan(&val); err != nil {

View file

@ -120,7 +120,10 @@ func (ts templateSystemEmbed) renderOrError(w http.ResponseWriter, template_name
return
}
buf.WriteTo(w)
_, err = buf.WriteTo(w)
if err != nil {
log.Error().Err(err).Msg("failed to write buffer on render")
}
}
func loadTemplateEmbedded(sourceFS fs.FS, path string) (*template.Template, error) {
content, err := fs.ReadFile(sourceFS, "template/"+path)

View file

@ -55,7 +55,10 @@ func (ts templateSystemDisk) renderOrError(w http.ResponseWriter, template_name
RespondError(w, "Failed to render template", err, http.StatusInternalServerError)
return
}
buf.WriteTo(w)
_, err = buf.WriteTo(w)
if err != nil {
log.Error().Err(err).Msg("failed to write buffer")
}
}
/*

View file

@ -7,6 +7,8 @@ import (
"io"
"net/http"
"time"
"github.com/rs/zerolog/log"
)
// Client represents a Label Studio API client
@ -58,7 +60,12 @@ func (c *Client) GetAccessToken() error {
if err != nil {
return fmt.Errorf("failed to send request: %w", err)
}
defer resp.Body.Close()
defer func() {
err := resp.Body.Close()
if err != nil {
log.Error().Err(err).Msg("failed to close body")
}
}()
// Check for successful response
if resp.StatusCode != http.StatusOK {
@ -110,7 +117,12 @@ func (c *Client) makeRequest(method string, path string, payload []byte) (*http.
// Check for successful response
if resp.StatusCode > http.StatusBadRequest {
defer resp.Body.Close()
defer func() {
err := resp.Body.Close()
if err != nil {
log.Error().Err(err).Msg("Failed to close body")
}
}()
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("Got status code %d and failed to read response body: %v", resp.StatusCode, err)

View file

@ -4,6 +4,8 @@ import (
"encoding/json"
"fmt"
"net/http"
"github.com/rs/zerolog/log"
)
// TaskImportResponse represents the response from the import tasks endpoint
@ -62,7 +64,12 @@ func (c *Client) ImportTasks(projectID int, tasks interface{}) (*TaskImportRespo
if err != nil {
return nil, fmt.Errorf("Failed to POST %s: %v", path, err)
}
defer resp.Body.Close()
defer func() {
err := resp.Body.Close()
if err != nil {
log.Error().Err(err).Msg("Failed to close body")
}
}()
// Check for successful response
if resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusOK {

View file

@ -56,10 +56,16 @@ func PrintPrettyStack(rvr interface{}) {
s := prettyStack{}
out, err := s.parse(debugStack, rvr)
if err == nil {
recovererErrorWriter.Write(out)
_, err = recovererErrorWriter.Write(out)
if err != nil {
os.Exit(101)
}
} else {
// print stdlib output as a fallback
os.Stderr.Write(debugStack)
_, err = os.Stderr.Write(debugStack)
if err != nil {
os.Exit(102)
}
}
}