lint: fix remaining errcheck for Write, Fprintf, Rollback, Commit

- Use lint.Write for unchecked w.Write in handlerJSONPost/Put, report
- Use lint.Fprintf for fmt.Fprintf in twilio handlers
- Use lint.LogOnErrRollback for deferred Rollbacks in compliance, lead, note
- Check errors from txn.Commit in lead, note
- Use lint.LogOnErrCtx for addError calls in flyover
This commit is contained in:
Eli Ribble 2026-05-09 02:41:49 +00:00
parent 679d12b48f
commit 808e172221
No known key found for this signature in database
7 changed files with 36 additions and 18 deletions

View file

@ -300,7 +300,7 @@ func handlerJSONPost[RequestType any, ResponseType any](f handlerFunctionPost[Re
respondErrorStatus(w, nhttp.NewError("failed to marshal json: %w", err))
return
}
w.Write(body)
lint.Write(w, body)
}
}
@ -323,7 +323,7 @@ func handlerJSONPut[RequestType any, ResponseType any](f handlerFunctionPost[Req
respondErrorStatus(w, nhttp.NewError("failed to marshal json: %w", err))
return
}
w.Write(body)
lint.Write(w, body)
}
}
func handlerFormPost[RequestType any, ResponseType any](f handlerFunctionPostFormMultipart[RequestType, ResponseType]) http.HandlerFunc {

View file

@ -7,6 +7,7 @@ import (
"strings"
"github.com/Gleipnir-Technology/nidus-sync/config"
"github.com/Gleipnir-Technology/nidus-sync/lint"
"github.com/Gleipnir-Technology/nidus-sync/platform/text"
"github.com/rs/zerolog/log"
"github.com/twilio/twilio-go/twiml"
@ -49,7 +50,7 @@ func splitPhoneSource(s string) (string, string) {
func twilioMessagePost(w http.ResponseWriter, r *http.Request) {
message_sid := r.PostFormValue("MessageSid")
log.Info().Str("sid", message_sid).Msg("Twilio Message POST")
fmt.Fprintf(w, "")
lint.Fprintf(w, "")
}
func twilioCallPost(w http.ResponseWriter, r *http.Request) {
called := r.PostFormValue("Called")
@ -93,7 +94,7 @@ func twilioCallPost(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
w.Header().Set("Content-Type", "text/xml")
fmt.Fprintf(w, "%s", twimlResult)
lint.Fprintf(w, "%s", twimlResult)
}
func twilioCallStatusPost(w http.ResponseWriter, r *http.Request) {
@ -108,7 +109,7 @@ func twilioCallStatusPost(w http.ResponseWriter, r *http.Request) {
caller_name := r.PostFormValue("CallerName")
parent_call_sid := r.PostFormValue("ParentCallSid")
log.Info().Str("call_sid", call_sid).Str("account_sid", account_sid).Str("from", from).Str("to", to).Str("call_status", call_status).Str("api_version", api_version).Str("direction", direction).Str("forwarded_from", forwarded_from).Str("caller_name", caller_name).Str("parent_call_sid", parent_call_sid)
fmt.Fprintf(w, "")
lint.Fprintf(w, "")
}
func twilioTextPost(w http.ResponseWriter, r *http.Request) {
message_sid := r.PostFormValue("MessageSid")
@ -147,12 +148,12 @@ func twilioTextPost(w http.ResponseWriter, r *http.Request) {
}
}()
w.Header().Set("Content-Type", "text/xml")
fmt.Fprintf(w, "%s", twiml)
lint.Fprintf(w, "%s", twiml)
}
func twilioTextStatusPost(w http.ResponseWriter, r *http.Request) {
message_sid := r.PostFormValue("MessageSid")
message_status := r.PostFormValue("MessageStatus")
log.Info().Str("sid", message_sid).Str("status", message_status).Msg("Updated message status")
text.UpdateMessageStatus(message_sid, message_status)
fmt.Fprintf(w, "")
lint.Fprintf(w, "")
}

View file

@ -10,6 +10,7 @@ import (
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
"github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/lint"
modelpublic "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/model"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
querypublic "github.com/Gleipnir-Technology/nidus-sync/db/query/public"
@ -25,7 +26,7 @@ func ComplianceRequestMailerCreate(ctx context.Context, user User, site_id int64
if err != nil {
return 0, fmt.Errorf("start txn: %w", err)
}
defer txn.Rollback(ctx)
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
site, err := querypublic.SiteFromIDForOrg(ctx, txn, site_id, int64(user.Organization.ID))
if err != nil {
return 0, fmt.Errorf("find site: %w", err)

View file

@ -14,6 +14,7 @@ import (
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
"github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/db/enums"
"github.com/Gleipnir-Technology/nidus-sync/lint"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/Gleipnir-Technology/nidus-sync/h3utils"
"github.com/Gleipnir-Technology/nidus-sync/platform/file"
@ -191,19 +192,25 @@ func insertFlyover(ctx context.Context, txn bob.Tx, file *models.FileuploadFile,
if err == nil {
setter.Condition = omit.From(condition)
} else {
addError(ctx, txn, c, int32(line_number), int32(i), fmt.Sprintf("'%s' is not a pool condition that we recognize. It should be one of %s", value, poolConditionValidValues()))
lint.LogOnErrCtx(func(ctx context.Context) error {
return addError(ctx, txn, c, int32(line_number), int32(i), fmt.Sprintf("'%s' is not a pool condition that we recognize. It should be one of %s", value, poolConditionValidValues()))
}, ctx, "add pool condition error")
continue
}
case headerFlyoverLatitude:
lat, err = strconv.ParseFloat(value, 10)
if err != nil {
addError(ctx, txn, c, int32(line_number), int32(i), fmt.Sprintf("'%s' is not decimal value", value))
lint.LogOnErrCtx(func(ctx context.Context) error {
return addError(ctx, txn, c, int32(line_number), int32(i), fmt.Sprintf("'%s' is not decimal value", value))
}, ctx, "add lat error")
continue
}
case headerFlyoverLongitude:
lng, err = strconv.ParseFloat(value, 10)
if err != nil {
addError(ctx, txn, c, int32(line_number), int32(i), fmt.Sprintf("'%s' is not decimal value", value))
lint.LogOnErrCtx(func(ctx context.Context) error {
return addError(ctx, txn, c, int32(line_number), int32(i), fmt.Sprintf("'%s' is not decimal value", value))
}, ctx, "add lng error")
continue
}
}

View file

@ -9,6 +9,7 @@ import (
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
"github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/lint"
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/model"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
query "github.com/Gleipnir-Technology/nidus-sync/db/query/public"
@ -23,13 +24,15 @@ func LeadCreate(ctx context.Context, user User, signal_id int32, site_id int32,
if err != nil {
return model.Lead{}, fmt.Errorf("start transaction: %w", err)
}
defer txn.Rollback(ctx)
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
lead, err := leadCreate(ctx, txn, user, signal_id, site_id, pool_location)
if err != nil {
return model.Lead{}, fmt.Errorf("inner leadcreate: %w", err)
}
txn.Commit(ctx)
if err := txn.Commit(ctx); err != nil {
return model.Lead{}, fmt.Errorf("commit: %w", err)
}
return lead, nil
}

View file

@ -6,6 +6,7 @@ import (
"strconv"
"github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/lint"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/Gleipnir-Technology/nidus-sync/platform/event"
//"github.com/google/uuid"
@ -17,7 +18,7 @@ func NoteAudioCreate(ctx context.Context, user User, setter models.NoteAudioSett
if err != nil {
return fmt.Errorf("create txn: %w", err)
}
defer txn.Rollback(ctx)
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
note_audio, err := models.NoteAudios.Insert(&setter).One(ctx, txn)
if err != nil {
@ -27,7 +28,9 @@ func NoteAudioCreate(ctx context.Context, user User, setter models.NoteAudioSett
}
}
event.Created(event.TypeNoteAudio, user.Organization.ID, strconv.Itoa(int(note_audio.ID)))
txn.Commit(ctx)
if err := txn.Commit(ctx); err != nil {
return fmt.Errorf("commit: %w", err)
}
return nil
}
@ -37,7 +40,7 @@ func NoteImageCreate(ctx context.Context, user User, setter models.NoteImageSett
if err != nil {
return fmt.Errorf("create txn: %w", err)
}
defer txn.Rollback(ctx)
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
note_image, err := models.NoteImages.Insert(&setter).One(ctx, db.PGInstance.BobDB)
if err != nil {
// Just ignore this failure, it means we already have this content
@ -46,7 +49,9 @@ func NoteImageCreate(ctx context.Context, user User, setter models.NoteImageSett
}
}
event.Created(event.TypeNoteImage, user.Organization.ID, strconv.Itoa(int(note_image.ID)))
txn.Commit(ctx)
if err := txn.Commit(ctx); err != nil {
return fmt.Errorf("commit: %w", err)
}
return err
}

View file

@ -10,6 +10,7 @@ import (
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
"github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/lint"
//"github.com/gorilla/mux"
"github.com/stephenafamo/scan"
//"github.com/rs/zerolog/log"
@ -78,7 +79,7 @@ func getReportSuggestion(w http.ResponseWriter, r *http.Request) {
return
}
w.Header().Set("Content-Type", "application/json")
w.Write(jsonBody)
lint.Write(w, jsonBody)
}
func partialSearchParam(p string) string {