lint: fix errcheck for txn calls, query results, and unchecked errors

- Fix Rollback/Commit in compliance.go, csv/csv.go, csv/pool.go
- Capture and check errors from .One() insert queries in send.go, text.go
- Check errors from markFunc, PopulateURL, and hydrate functions
- Use lint.LogOnErrCtx for best-effort notification sends
This commit is contained in:
Eli Ribble 2026-05-09 02:35:55 +00:00
parent 0ec810591e
commit 679d12b48f
No known key found for this signature in database
10 changed files with 47 additions and 16 deletions

View file

@ -100,7 +100,9 @@ func ComplianceRequestMailerCreate(ctx context.Context, user User, site_id int64
return 0, fmt.Errorf("create background compliance mailer job: %w", err)
}
event.Updated(event.TypeSite, user.Organization.ID, strconv.Itoa(int(site.ID)))
txn.Commit(ctx)
if err := txn.Commit(ctx); err != nil {
return 0, fmt.Errorf("commit: %w", err)
}
return req.ID, nil
}

View file

@ -15,6 +15,7 @@ import (
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
//"github.com/Gleipnir-Technology/nidus-sync/config"
"github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/lint"
"github.com/Gleipnir-Technology/nidus-sync/db/enums"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/Gleipnir-Technology/nidus-sync/platform/event"
@ -65,7 +66,7 @@ func JobCommit(ctx context.Context, file_id int32) error {
if err != nil {
return fmt.Errorf("begin transaction: %w", err)
}
defer txn.Rollback(ctx)
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
for _, row := range rows {
var a *types.Address
var parcel *models.Parcel
@ -179,7 +180,7 @@ func JobCommit(ctx context.Context, file_id int32) error {
return fmt.Errorf("update file status to committed: %w", err)
}
event.Updated(event.TypeFileCSV, file.OrganizationID, strconv.Itoa(int(file.ID)))
defer txn.Commit(ctx)
lint.LogOnErrCtx(txn.Commit, ctx, "commit")
return nil
}
func JobImport(ctx context.Context, file_id int32) error {
@ -238,7 +239,7 @@ func importCSV[T any](ctx context.Context, file_id int32, parser csvParserFunc[T
if err != nil {
return fmt.Errorf("Failed to start transaction: %w", err)
}
defer txn.Rollback(ctx)
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
parsed, err := parser(ctx, txn, file, c)
if err != nil {
return fmt.Errorf("parse file: %w", err)
@ -263,7 +264,9 @@ func importCSV[T any](ctx context.Context, file_id int32, parser csvParserFunc[T
return fmt.Errorf("update: %w", err)
}
log.Info().Int32("file.ID", file.ID).Msg("Set file to parsed")
txn.Commit(ctx)
if err := txn.Commit(ctx); err != nil {
return fmt.Errorf("commit: %w", err)
}
return nil
}
func loadFileAndCSV(ctx context.Context, file_id int32) (*models.FileuploadFile, *models.FileuploadCSV, error) {

View file

@ -13,6 +13,7 @@ import (
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
"github.com/Gleipnir-Technology/nidus-sync/config"
"github.com/Gleipnir-Technology/nidus-sync/lint"
"github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/db/enums"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
@ -109,7 +110,7 @@ func bulkGeocode(ctx context.Context, txn bob.Tx, file *models.FileuploadFile, c
error_count++
}
if error_count > 0 {
txn.Rollback(ctx)
lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
return fmt.Errorf("%d errors encountered in bulk geocode", error_count)
}
update_query := `

View file

@ -7,6 +7,7 @@ import (
"github.com/Gleipnir-Technology/bob"
"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/email"
"github.com/Gleipnir-Technology/nidus-sync/platform/text"
@ -41,7 +42,9 @@ func RegisterNotificationEmail(ctx context.Context, txn bob.Executor, report_id
if err != nil {
return err
}
email.SendReportConfirmation(ctx, destination, report_id)
lint.LogOnErrCtx(func(ctx context.Context) error {
return email.SendReportConfirmation(ctx, destination, report_id)
}, ctx, "send report confirmation")
return nil
}
@ -58,7 +61,9 @@ func RegisterNotificationPhone(ctx context.Context, txn bob.Executor, report_id
if err != nil {
return err
}
text.ReportSubscriptionConfirmationText(ctx, db.PGInstance.BobDB, phone, report.PublicID)
lint.LogOnErrCtx(func(ctx context.Context) error {
return text.ReportSubscriptionConfirmationText(ctx, db.PGInstance.BobDB, phone, report.PublicID)
}, ctx, "report subscription confirmation text")
return nil
}

View file

@ -47,11 +47,14 @@ func ReviewPoolCreate(ctx context.Context, user User, task_id int32, status stri
if err != nil {
return 0, fmt.Errorf("status '%s' is not recognized: %w", status, err)
}
review_task.Update(ctx, txn, &models.ReviewTaskSetter{
err = review_task.Update(ctx, txn, &models.ReviewTaskSetter{
Resolution: omitnull.From(resolution),
Reviewed: omitnull.From(time.Now()),
ReviewerID: omitnull.From(int32(user.ID)),
})
if err != nil {
return 0, fmt.Errorf("update review task: %w", err)
}
review_task_pool, err := models.ReviewTaskPools.Query(
models.SelectWhere.ReviewTaskPools.ReviewTaskID.EQ(review_task.ID),
).One(ctx, txn)

View file

@ -43,9 +43,12 @@ func setPhoneStatus(ctx context.Context, txn bob.Executor, src types.E164, statu
if err != nil {
return fmt.Errorf("Failed to determine if '%s' is subscribed: %w", src, err)
}
phone.Update(ctx, txn, &models.CommsPhoneSetter{
err = phone.Update(ctx, txn, &models.CommsPhoneSetter{
Status: omit.From(status),
})
if err != nil {
return fmt.Errorf("update phone status: %w", err)
}
log.Info().Str("src", src.PhoneString()).Str("status", string(status)).Msg("Set number subscribed")
return nil
}

View file

@ -159,7 +159,7 @@ func sendTextComplete(ctx context.Context, job *models.CommsTextJob) error {
if err != nil {
return fmt.Errorf("insert report_text: %w", err)
}
models.PublicreportReportLogs.Insert(&models.PublicreportReportLogSetter{
_, err = models.PublicreportReportLogs.Insert(&models.PublicreportReportLogSetter{
Created: omit.From(time.Now()),
EmailLogID: omitnull.FromPtr[int32](nil),
// ID
@ -168,6 +168,9 @@ func sendTextComplete(ctx context.Context, job *models.CommsTextJob) error {
Type: omit.From(enums.PublicreportReportlogtypeMessageText),
UserID: omitnull.From(creator_id),
}).One(ctx, txn)
if err != nil {
return fmt.Errorf("insert report log: %w", err)
}
report, err := models.FindPublicreportReport(ctx, txn, report_id)
if err != nil {
return fmt.Errorf("find public report: %w", err)

View file

@ -136,7 +136,7 @@ func respondText(ctx context.Context, log_id int32) error {
return fmt.Errorf("has open report: %w", err)
}
for _, report := range reports {
models.PublicreportReportLogs.Insert(&models.PublicreportReportLogSetter{
_, err = models.PublicreportReportLogs.Insert(&models.PublicreportReportLogSetter{
Created: omit.From(time.Now()),
EmailLogID: omitnull.FromPtr[int32](nil),
// ID
@ -145,6 +145,9 @@ func respondText(ctx context.Context, log_id int32) error {
Type: omit.From(enums.PublicreportReportlogtypeMessageText),
UserID: omitnull.FromPtr[int32](nil),
}).One(ctx, txn)
if err != nil {
return fmt.Errorf("insert report log: %w", err)
}
event.Updated(event.TypeRMOPublicReport, report.OrganizationID, report.PublicID)
}
// If humans are involved, wait for them.

View file

@ -194,7 +194,9 @@ func (res *communicationR) markCommunication(ctx context.Context, r *http.Reques
if err != nil {
return communication{}, nhttp.NewBadRequest("can't turn report ID into an int: %w", err)
}
m(ctx, user, int32(comm_id))
if err := m(ctx, user, int32(comm_id)); err != nil {
return communication{}, nhttp.NewError("mark communication: %w", err)
}
result, err := platform.CommunicationFromID(ctx, user, int64(comm_id))
if result == nil {
return communication{}, nhttp.NewUnauthorized("you are not authorized to modify communication %d", comm_id)

View file

@ -269,10 +269,16 @@ func (res *complianceR) byID(ctx context.Context, r *http.Request, is_public boo
return res.complianceHydrate(report, is_public)
}
func (res *complianceR) complianceHydrate(report *types.PublicReportCompliance, is_public bool) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) {
populateDistrictURI(&report.PublicReport, res.router)
populateReportURI(&report.PublicReport, res.router, is_public)
if err := populateDistrictURI(&report.PublicReport, res.router); err != nil {
return nil, nhttp.NewError("populate district URI: %w", err)
}
if err := populateReportURI(&report.PublicReport, res.router, is_public); err != nil {
return nil, nhttp.NewError("populate report URI: %w", err)
}
for _, e := range report.Concerns {
e.PopulateURL(res.router.router)
if err := e.PopulateURL(res.router.router); err != nil {
return nil, nhttp.NewError("populate concern URL: %w", err)
}
}
return report, nil
}