lint: fix remaining errcheck issues across multiple files
- Fix renderShim errcheck in district.go, image.go - Fix txn.Rollback/Commit in publicreport.go, notification, review, signal, upload - Fix addError calls in csv/flyover.go, csv/pool.go - Fix cW/write calls in logger.go, recoverer.go, voipms.go - Fix resendInitialText, handleWaitingTextJobs, setPhoneStatus in text/send.go, text.go - Fix populateDistrictURI/populateReportURI in resource files
This commit is contained in:
parent
808e172221
commit
7270de2937
16 changed files with 141 additions and 63 deletions
|
|
@ -33,12 +33,16 @@ func apiGetDistrict(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
lng, err := strconv.ParseFloat(lngStr, 64)
|
||||
if err != nil {
|
||||
renderShim(w, r, errRender(fmt.Errorf("Failed to parse lng as float: %w", err)))
|
||||
if err := renderShim(w, r, errRender(fmt.Errorf("Failed to parse lng as float: %w", err))); err != nil {
|
||||
http.Error(w, fmt.Sprintf("render shim: %v", err), http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
}
|
||||
org, err := platform.DistrictForLocation(r.Context(), lng, lat)
|
||||
if err != nil {
|
||||
renderShim(w, r, errRender(fmt.Errorf("Failed to get district: %w", err)))
|
||||
if err := renderShim(w, r, errRender(fmt.Errorf("Failed to get district: %w", err))); err != nil {
|
||||
http.Error(w, fmt.Sprintf("render shim: %v", err), http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
}
|
||||
if org == nil {
|
||||
|
|
@ -52,7 +56,9 @@ func apiGetDistrict(w http.ResponseWriter, r *http.Request) {
|
|||
Website: org.Website.GetOr(""),
|
||||
}
|
||||
if err := renderShim(w, r, d); err != nil {
|
||||
renderShim(w, r, errRender(err))
|
||||
if err := renderShim(w, r, errRender(err)); err != nil {
|
||||
http.Error(w, fmt.Sprintf("render shim: %v", err), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -351,7 +351,7 @@ func handlerFormPost[RequestType any, ResponseType any](f handlerFunctionPostFor
|
|||
respondErrorStatus(w, nhttp.NewError("failed to marshal json: %w", err))
|
||||
return
|
||||
}
|
||||
w.Write(body)
|
||||
lint.Write(w, body)
|
||||
}
|
||||
}
|
||||
func parseRequest[RequestType any](r *http.Request) (*RequestType, *nhttp.ErrorWithStatus) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package api
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
|
|
@ -48,7 +49,9 @@ func apiImagePost(w http.ResponseWriter, r *http.Request, u platform.User) {
|
|||
}
|
||||
err = platform.NoteImageCreate(ctx, u, setter)
|
||||
if err != nil {
|
||||
renderShim(w, r, errRender(err))
|
||||
if err := renderShim(w, r, errRender(err)); err != nil {
|
||||
http.Error(w, fmt.Sprintf("render shim: %v", err), http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
|
|
@ -75,7 +78,9 @@ func apiImageContentPost(w http.ResponseWriter, r *http.Request, u platform.User
|
|||
}
|
||||
err = file.ImageFileFromReader(file.CollectionImageRaw, imageUUID, r.Body)
|
||||
if err != nil {
|
||||
renderShim(w, r, errRender(err))
|
||||
if err := renderShim(w, r, errRender(err)); err != nil {
|
||||
http.Error(w, fmt.Sprintf("render shim: %v", err), http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@ package api
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
//"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"
|
||||
)
|
||||
|
|
@ -101,5 +101,5 @@ func voipmsTextPost(w http.ResponseWriter, r *http.Request) {
|
|||
log.Error().Err(err).Msg("failed to handle VoIP.ms incoming text")
|
||||
}
|
||||
}()
|
||||
fmt.Fprintf(w, "ok")
|
||||
lint.Fprintf(w, "ok")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,16 +106,16 @@ func (l *DefaultLogFormatter) NewLogEntry(r *http.Request) LogEntry {
|
|||
|
||||
reqID := GetReqID(r.Context())
|
||||
if reqID != "" {
|
||||
cW(entry.buf, useColor, nYellow, "[%s] ", reqID)
|
||||
_ = cW(entry.buf, useColor, nYellow, "[%s] ", reqID)
|
||||
}
|
||||
cW(entry.buf, useColor, nCyan, "\"")
|
||||
cW(entry.buf, useColor, bMagenta, "%s ", r.Method)
|
||||
_ = cW(entry.buf, useColor, nCyan, "\"")
|
||||
_ = cW(entry.buf, useColor, bMagenta, "%s ", r.Method)
|
||||
|
||||
scheme := "http"
|
||||
if r.TLS != nil {
|
||||
scheme = "https"
|
||||
}
|
||||
cW(entry.buf, useColor, nCyan, "%s://%s%s %s\" ", scheme, r.Host, r.RequestURI, r.Proto)
|
||||
_ = cW(entry.buf, useColor, nCyan, "%s://%s%s %s\" ", scheme, r.Host, r.RequestURI, r.Proto)
|
||||
|
||||
entry.buf.WriteString("from ")
|
||||
entry.buf.WriteString(r.RemoteAddr)
|
||||
|
|
@ -134,26 +134,26 @@ type defaultLogEntry struct {
|
|||
func (l *defaultLogEntry) Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{}) {
|
||||
switch {
|
||||
case status < 200:
|
||||
cW(l.buf, l.useColor, bBlue, "%03d", status)
|
||||
_ = cW(l.buf, l.useColor, bBlue, "%03d", status)
|
||||
case status < 300:
|
||||
cW(l.buf, l.useColor, bGreen, "%03d", status)
|
||||
_ = cW(l.buf, l.useColor, bGreen, "%03d", status)
|
||||
case status < 400:
|
||||
cW(l.buf, l.useColor, bCyan, "%03d", status)
|
||||
_ = cW(l.buf, l.useColor, bCyan, "%03d", status)
|
||||
case status < 500:
|
||||
cW(l.buf, l.useColor, bYellow, "%03d", status)
|
||||
_ = cW(l.buf, l.useColor, bYellow, "%03d", status)
|
||||
default:
|
||||
cW(l.buf, l.useColor, bRed, "%03d", status)
|
||||
_ = cW(l.buf, l.useColor, bRed, "%03d", status)
|
||||
}
|
||||
|
||||
cW(l.buf, l.useColor, bBlue, " %dB", bytes)
|
||||
_ = cW(l.buf, l.useColor, bBlue, " %dB", bytes)
|
||||
|
||||
l.buf.WriteString(" in ")
|
||||
if elapsed < 500*time.Millisecond {
|
||||
cW(l.buf, l.useColor, nGreen, "%s", elapsed)
|
||||
_ = cW(l.buf, l.useColor, nGreen, "%s", elapsed)
|
||||
} else if elapsed < 5*time.Second {
|
||||
cW(l.buf, l.useColor, nYellow, "%s", elapsed)
|
||||
_ = cW(l.buf, l.useColor, nYellow, "%s", elapsed)
|
||||
} else {
|
||||
cW(l.buf, l.useColor, nRed, "%s", elapsed)
|
||||
_ = cW(l.buf, l.useColor, nRed, "%s", elapsed)
|
||||
}
|
||||
|
||||
l.Logger.Print(l.buf.String())
|
||||
|
|
|
|||
|
|
@ -317,7 +317,9 @@ func insertPoollistRow(ctx context.Context, txn bob.Tx, file *models.FileuploadF
|
|||
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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,11 +153,15 @@ func geocodePool(ctx context.Context, txn bob.Tx, client *stadia.StadiaMaps, job
|
|||
}
|
||||
geo, err := geocode.GeocodeStructured(ctx, job.org, a)
|
||||
if err != nil {
|
||||
addError(ctx, txn, job.csv, pool.LineNumber, 0, err.Error())
|
||||
lint.LogOnErrCtx(func(ctx context.Context) error {
|
||||
return addError(ctx, txn, job.csv, pool.LineNumber, 0, err.Error())
|
||||
}, ctx, "add geocode error")
|
||||
return nil
|
||||
}
|
||||
if geo.Address.Location == nil {
|
||||
addError(ctx, txn, job.csv, pool.LineNumber, 0, "nil location from geocoding")
|
||||
lint.LogOnErrCtx(func(ctx context.Context) error {
|
||||
return addError(ctx, txn, job.csv, pool.LineNumber, 0, "nil location from geocoding")
|
||||
}, ctx, "add nil location error")
|
||||
return nil
|
||||
}
|
||||
geom_query := geom.PostgisPointQuery(*geo.Address.Location)
|
||||
|
|
@ -187,7 +191,9 @@ func parseCSVPoollist(ctx context.Context, txn bob.Tx, f *models.FileuploadFile,
|
|||
header_types, header_names := parseHeaders(h)
|
||||
missing_headers := missingRequiredHeaders(header_types)
|
||||
for _, mh := range missing_headers {
|
||||
errorMissingHeader(ctx, txn, c, mh)
|
||||
lint.LogOnErrCtx(func(ctx context.Context) error {
|
||||
return errorMissingHeader(ctx, txn, c, mh)
|
||||
}, ctx, "error missing header")
|
||||
err = f.Update(ctx, txn, &models.FileuploadFileSetter{
|
||||
Status: omit.From(enums.FileuploadFilestatustypeError),
|
||||
})
|
||||
|
|
@ -253,7 +259,9 @@ func parseCSVPoollist(ctx context.Context, txn bob.Tx, f *models.FileuploadFile,
|
|||
// This type of spreadsheet normally has '123 Main Str'
|
||||
parts := strings.SplitN(col, " ", 2)
|
||||
if len(parts) != 2 {
|
||||
addError(ctx, txn, c, int32(line_number), int32(i), fmt.Sprintf("'%s' is not a house number and street. It needs to be in the form '123 main'", col))
|
||||
lint.LogOnErrCtx(func(ctx context.Context) error {
|
||||
return addError(ctx, txn, c, int32(line_number), int32(i), fmt.Sprintf("'%s' is not a house number and street. It needs to be in the form '123 main'", col))
|
||||
}, ctx, "add address parse error")
|
||||
continue
|
||||
}
|
||||
setter.AddressNumber = omit.From(parts[0])
|
||||
|
|
@ -268,7 +276,9 @@ func parseCSVPoollist(ctx context.Context, txn bob.Tx, f *models.FileuploadFile,
|
|||
}
|
||||
err := condition.Scan(col_translated)
|
||||
if err != nil {
|
||||
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", col, 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", col, poolConditionValidValues()))
|
||||
}, ctx, "add pool condition error")
|
||||
setter.Condition = omit.From(enums.PoolconditiontypeUnknown)
|
||||
continue
|
||||
}
|
||||
|
|
@ -280,7 +290,9 @@ func parseCSVPoollist(ctx context.Context, txn bob.Tx, f *models.FileuploadFile,
|
|||
case headerPoolPropertyOwnerPhone:
|
||||
phone, err := text.ParsePhoneNumber(col)
|
||||
if err != nil {
|
||||
addError(ctx, txn, c, int32(line_number), int32(i), fmt.Sprintf("'%s' is not a phone number that we recognize. Ideally it should be of the form '+12223334444'", col))
|
||||
lint.LogOnErrCtx(func(ctx context.Context) error {
|
||||
return addError(ctx, txn, c, int32(line_number), int32(i), fmt.Sprintf("'%s' is not a phone number that we recognize. Ideally it should be of the form '+12223334444'", col))
|
||||
}, ctx, "add phone number error")
|
||||
continue
|
||||
}
|
||||
err = text.EnsureInDB(ctx, txn, *phone)
|
||||
|
|
@ -292,14 +304,18 @@ func parseCSVPoollist(ctx context.Context, txn bob.Tx, f *models.FileuploadFile,
|
|||
case headerPoolResidentOwned:
|
||||
boolValue, err := parseBool(col)
|
||||
if err != nil {
|
||||
addError(ctx, txn, c, int32(line_number), int32(i), fmt.Sprintf("'%s' is not something that we recognize as a true/false value. Please use either 'true' or 'false'", col))
|
||||
lint.LogOnErrCtx(func(ctx context.Context) error {
|
||||
return addError(ctx, txn, c, int32(line_number), int32(i), fmt.Sprintf("'%s' is not something that we recognize as a true/false value. Please use either 'true' or 'false'", col))
|
||||
}, ctx, "add bool error")
|
||||
continue
|
||||
}
|
||||
setter.ResidentOwned = omitnull.From(boolValue)
|
||||
case headerPoolResidentPhone:
|
||||
phone, err := text.ParsePhoneNumber(col)
|
||||
if err != nil {
|
||||
addError(ctx, txn, c, int32(line_number), int32(i), fmt.Sprintf("'%s' is not a phone number that we recognize. Ideally it should be of the form '+12223334444'", col))
|
||||
lint.LogOnErrCtx(func(ctx context.Context) error {
|
||||
return addError(ctx, txn, c, int32(line_number), int32(i), fmt.Sprintf("'%s' is not a phone number that we recognize. Ideally it should be of the form '+12223334444'", col))
|
||||
}, ctx, "add phone number error")
|
||||
continue
|
||||
}
|
||||
err = text.EnsureInDB(ctx, txn, *phone)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"github.com/Gleipnir-Technology/jet/postgres"
|
||||
"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"
|
||||
tablepublic "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/table"
|
||||
modelpublicreport "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/publicreport/model"
|
||||
|
|
@ -109,7 +110,7 @@ func PublicReportMessageCreate(ctx context.Context, user User, public_id, messag
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("create txn: %w", err)
|
||||
}
|
||||
defer txn.Rollback(ctx)
|
||||
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
|
||||
|
||||
report, err := querypublicreport.ReportFromPublicID(ctx, db.PGInstance.PGXPool, public_id)
|
||||
if err != nil {
|
||||
|
|
@ -128,7 +129,9 @@ func PublicReportMessageCreate(ctx context.Context, user User, public_id, messag
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("send text: %w", err)
|
||||
}
|
||||
txn.Commit(ctx)
|
||||
if err := txn.Commit(ctx); err != nil {
|
||||
return nil, fmt.Errorf("commit: %w", err)
|
||||
}
|
||||
//log.Debug().Int32("msg_id", *msg_id).Msg("Created text.ReportMessage")
|
||||
return msg_id, nil
|
||||
} else if report.ReporterEmail != "" {
|
||||
|
|
@ -136,7 +139,9 @@ func PublicReportMessageCreate(ctx context.Context, user User, public_id, messag
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("send email: %w", err)
|
||||
}
|
||||
txn.Commit(ctx)
|
||||
if err := txn.Commit(ctx); err != nil {
|
||||
return nil, fmt.Errorf("commit: %w", err)
|
||||
}
|
||||
return msg_id, nil
|
||||
} else {
|
||||
log.Debug().Str("public_id", public_id).Msg("contacting via email")
|
||||
|
|
@ -149,7 +154,7 @@ func PublicReportUpdateCompliance(ctx context.Context, public_id string, report_
|
|||
if err != nil {
|
||||
return fmt.Errorf("create txn: %w", err)
|
||||
}
|
||||
defer txn.Rollback(ctx)
|
||||
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
|
||||
report, err := querypublicreport.ReportFromPublicID(ctx, db.PGInstance.PGXPool, public_id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("query report existence: %w", err)
|
||||
|
|
@ -213,7 +218,9 @@ func PublicReportUpdateCompliance(ctx context.Context, public_id string, report_
|
|||
return fmt.Errorf("update location: %w", err)
|
||||
}
|
||||
}
|
||||
txn.Commit(ctx)
|
||||
if err := txn.Commit(ctx); err != nil {
|
||||
return fmt.Errorf("commit: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func PublicReportReporterUpdated(ctx context.Context, org_id int32, report_id string) {
|
||||
|
|
@ -240,7 +247,7 @@ func PublicReportImageCreate(ctx context.Context, public_id string, images []Ima
|
|||
if err != nil {
|
||||
return fmt.Errorf("create txn: %w", err)
|
||||
}
|
||||
defer txn.Rollback(ctx)
|
||||
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
|
||||
|
||||
report, err := querypublicreport.ReportFromPublicID(ctx, db.PGInstance.PGXPool, public_id)
|
||||
if err != nil {
|
||||
|
|
@ -264,7 +271,9 @@ func PublicReportImageCreate(ctx context.Context, public_id string, images []Ima
|
|||
}
|
||||
log.Info().Int("len", len(images)).Msg("saved uploaded images")
|
||||
}
|
||||
txn.Commit(ctx)
|
||||
if err := txn.Commit(ctx); err != nil {
|
||||
return fmt.Errorf("commit: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func PublicReportNuisanceCreate(ctx context.Context, setter_report modelpublicreport.Report, setter_nuisance modelpublicreport.Nuisance, location types.Location, address Address, images []ImageUpload) (modelpublicreport.Report, error) {
|
||||
|
|
@ -303,7 +312,7 @@ func publicReportCreate(ctx context.Context, setter_report modelpublicreport.Rep
|
|||
if err != nil {
|
||||
return result, fmt.Errorf("create txn: %w", err)
|
||||
}
|
||||
defer txn.Rollback(ctx)
|
||||
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
|
||||
|
||||
if setter_report.PublicID == "" {
|
||||
public_id, err := GenerateReportID()
|
||||
|
|
@ -354,7 +363,9 @@ func publicReportCreate(ctx context.Context, setter_report modelpublicreport.Rep
|
|||
if location != nil {
|
||||
l := *location
|
||||
if l.Latitude != 0 && l.Longitude != 0 {
|
||||
publicReportUpdateLocation(ctx, txn, result.ID, l)
|
||||
lint.LogOnErrCtx(func(ctx context.Context) error {
|
||||
return publicReportUpdateLocation(ctx, txn, result.ID, l)
|
||||
}, ctx, "update location")
|
||||
}
|
||||
}
|
||||
log.Info().Str("public_id", setter_report.PublicID).Int32("id", result.ID).Msg("Created base report")
|
||||
|
|
@ -403,7 +414,9 @@ func publicReportCreate(ctx context.Context, setter_report modelpublicreport.Rep
|
|||
log.Debug().Int32("id", comm.ID).Msg("inserted new communication")
|
||||
}
|
||||
|
||||
txn.Commit(ctx)
|
||||
if err := txn.Commit(ctx); err != nil {
|
||||
return result, fmt.Errorf("commit: %w", err)
|
||||
}
|
||||
|
||||
event.Created(
|
||||
event.TypeRMOPublicReport,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"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/report"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
|
||||
|
|
@ -26,7 +27,7 @@ func PublicreportNotificationCreate(ctx context.Context, pn PublicreportNotifica
|
|||
if err != nil {
|
||||
return fmt.Errorf("begin txn: %w", err)
|
||||
}
|
||||
defer txn.Rollback(ctx)
|
||||
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
|
||||
rep, err := models.PublicreportReports.Query(
|
||||
models.SelectWhere.PublicreportReports.PublicID.EQ(pn.ReportID),
|
||||
).One(ctx, db.PGInstance.BobDB)
|
||||
|
|
@ -66,7 +67,9 @@ func PublicreportNotificationCreate(ctx context.Context, pn PublicreportNotifica
|
|||
}
|
||||
}
|
||||
}
|
||||
txn.Commit(ctx)
|
||||
if err := txn.Commit(ctx); err != nil {
|
||||
return fmt.Errorf("commit: %w", err)
|
||||
}
|
||||
PublicReportReporterUpdated(ctx, rep.OrganizationID, pn.ReportID)
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,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"
|
||||
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/event"
|
||||
|
|
@ -31,7 +32,7 @@ func ReviewPoolCreate(ctx context.Context, user User, task_id int32, status stri
|
|||
if err != nil {
|
||||
return 0, nhttp.NewError("start txn: %w", err)
|
||||
}
|
||||
defer txn.Rollback(ctx)
|
||||
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
|
||||
review_task, err := models.ReviewTasks.Query(
|
||||
models.SelectWhere.ReviewTasks.ID.EQ(task_id),
|
||||
models.SelectWhere.ReviewTasks.OrganizationID.EQ(user.Organization.ID),
|
||||
|
|
@ -70,7 +71,9 @@ func ReviewPoolCreate(ctx context.Context, user User, task_id int32, status stri
|
|||
return 0, err
|
||||
}
|
||||
event.Updated(event.TypeReviewTask, user.Organization.ID, strconv.Itoa(int(review_task.ID)))
|
||||
txn.Commit(ctx)
|
||||
if err := txn.Commit(ctx); err != nil {
|
||||
return 0, nhttp.NewError("commit: %w", err)
|
||||
}
|
||||
log.Info().Int32("id", review_task.ID).Str("status", status).Msg("review completed")
|
||||
return review_task.ID, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,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"
|
||||
modelpublicreport "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/publicreport/model"
|
||||
tablepublicreport "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/publicreport/table"
|
||||
|
|
@ -69,7 +70,7 @@ func SignalCreateFromPool(ctx context.Context, txn db.Ex, user User, site_id int
|
|||
// Create a lead from the given signal and site
|
||||
func SignalCreateFromPublicreport(ctx context.Context, user User, report_id string) (*int32, error) {
|
||||
txn, err := db.BeginTxn(ctx)
|
||||
defer txn.Rollback(ctx)
|
||||
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("start transaction: %w", err)
|
||||
}
|
||||
|
|
@ -166,7 +167,9 @@ func SignalCreateFromPublicreport(ctx context.Context, user User, report_id stri
|
|||
return nil, fmt.Errorf("failed to update report %d: %w", report_id, err)
|
||||
}
|
||||
event.Created(event.TypeSignal, user.Organization.ID, strconv.Itoa(int(signal.ID)))
|
||||
txn.Commit(ctx)
|
||||
if err := txn.Commit(ctx); err != nil {
|
||||
return nil, fmt.Errorf("commit: %w", err)
|
||||
}
|
||||
|
||||
return &signal.ID, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||
"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/platform/background"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/event"
|
||||
|
|
@ -105,7 +106,7 @@ func sendTextComplete(ctx context.Context, job *models.CommsTextJob) error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("begin tx: %w", err)
|
||||
}
|
||||
defer txn.Rollback(ctx)
|
||||
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
|
||||
dst, err := ParsePhoneNumber(job.Destination)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parse phone: %w", err)
|
||||
|
|
@ -134,7 +135,9 @@ func sendTextComplete(ctx context.Context, job *models.CommsTextJob) error {
|
|||
//case enums.CommsPhonestatustypeOkToSend:
|
||||
// allow to drop through
|
||||
case enums.CommsPhonestatustypeStopped:
|
||||
resendInitialText(ctx, txn, *dst)
|
||||
lint.LogOnErrCtx(func(ctx context.Context) error {
|
||||
return resendInitialText(ctx, txn, *dst)
|
||||
}, ctx, "resend initial text")
|
||||
return nil
|
||||
}
|
||||
text_log, err := sendTextDirect(ctx, txn, origin, job.Destination, job.Content, true, false)
|
||||
|
|
@ -179,7 +182,9 @@ func sendTextComplete(ctx context.Context, job *models.CommsTextJob) error {
|
|||
} else {
|
||||
log.Debug().Msg("no report info on text")
|
||||
}
|
||||
txn.Commit(ctx)
|
||||
if err := txn.Commit(ctx); err != nil {
|
||||
return fmt.Errorf("commit: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||
"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/platform/background"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/event"
|
||||
|
|
@ -32,7 +33,7 @@ func HandleTextMessage(ctx context.Context, source string, destination string, c
|
|||
if err != nil {
|
||||
return fmt.Errorf("start txn: %w", err)
|
||||
}
|
||||
defer txn.Rollback(ctx)
|
||||
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
|
||||
|
||||
status, err := phoneStatus(ctx, *src)
|
||||
if err != nil {
|
||||
|
|
@ -60,7 +61,9 @@ func HandleTextMessage(ctx context.Context, source string, destination string, c
|
|||
if err != nil {
|
||||
return fmt.Errorf("text respond: %w", err)
|
||||
}
|
||||
txn.Commit(ctx)
|
||||
if err := txn.Commit(ctx); err != nil {
|
||||
return fmt.Errorf("commit: %w", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +72,7 @@ func respondText(ctx context.Context, log_id int32) error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("begin tx: %w", err)
|
||||
}
|
||||
defer txn.Rollback(ctx)
|
||||
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
|
||||
l, err := models.FindCommsTextLog(ctx, txn, log_id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("find comms: %w", err)
|
||||
|
|
@ -98,7 +101,9 @@ func respondText(ctx context.Context, log_id int32) error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("send response: %w", err)
|
||||
}
|
||||
handleWaitingTextJobs(ctx, *src)
|
||||
lint.LogOnErrCtx(func(ctx context.Context) error {
|
||||
return handleWaitingTextJobs(ctx, *src)
|
||||
}, ctx, "handle waiting text jobs")
|
||||
// We don't handle 'stop' here because we allow them to say 'stop' at any time, regardless of
|
||||
// phone status.
|
||||
//case "stop":
|
||||
|
|
@ -118,7 +123,9 @@ func respondText(ctx context.Context, log_id int32) error {
|
|||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to send unsubscribe acknowledgement.")
|
||||
}
|
||||
setPhoneStatus(ctx, txn, *src, enums.CommsPhonestatustypeStopped)
|
||||
lint.LogOnErrCtx(func(ctx context.Context) error {
|
||||
return setPhoneStatus(ctx, txn, *src, enums.CommsPhonestatustypeStopped)
|
||||
}, ctx, "set phone status")
|
||||
return nil
|
||||
case "reset conversation":
|
||||
err = handleResetConversation(ctx, txn, *src)
|
||||
|
|
@ -172,12 +179,14 @@ func respondTextLLM(ctx context.Context, src types.E164) error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("start txn: %w", err)
|
||||
}
|
||||
defer txn.Rollback(ctx)
|
||||
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
|
||||
_, err = sendTextDirect(ctx, txn, enums.CommsTextoriginLLM, src.PhoneString(), next_message.Content, true, false)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to send response text: %w", err)
|
||||
}
|
||||
txn.Commit(ctx)
|
||||
if err := txn.Commit(ctx); err != nil {
|
||||
return fmt.Errorf("commit: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
||||
"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/background"
|
||||
|
|
@ -86,7 +87,7 @@ func NewUpload(ctx context.Context, u User, upload file.Upload, t enums.Fileuplo
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to begin transaction: %w", err)
|
||||
}
|
||||
defer txn.Rollback(ctx)
|
||||
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
|
||||
|
||||
file, err := models.FileuploadFiles.Insert(&models.FileuploadFileSetter{
|
||||
ContentType: omit.From(upload.ContentType),
|
||||
|
|
@ -117,7 +118,9 @@ func NewUpload(ctx context.Context, u User, upload file.Upload, t enums.Fileuplo
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("background job create: %w", err)
|
||||
}
|
||||
txn.Commit(ctx)
|
||||
if err := txn.Commit(ctx); err != nil {
|
||||
return nil, fmt.Errorf("commit: %w", err)
|
||||
}
|
||||
return &file.ID, nil
|
||||
}
|
||||
func UploadCommit(ctx context.Context, org Organization, file_id int32, committer User) error {
|
||||
|
|
@ -125,7 +128,7 @@ func UploadCommit(ctx context.Context, org Organization, file_id int32, committe
|
|||
if err != nil {
|
||||
return fmt.Errorf("Failed to begin transaction: %w", err)
|
||||
}
|
||||
defer txn.Rollback(ctx)
|
||||
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
|
||||
|
||||
_, err = psql.Update(
|
||||
um.Table(models.FileuploadFiles.Alias()),
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
//tablepublicreport "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/publicreport/table"
|
||||
//querypublicreport "github.com/Gleipnir-Technology/nidus-sync/db/query/publicreport"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/html"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/lint"
|
||||
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
|
||||
|
|
@ -150,7 +151,11 @@ func (res *nuisanceR) byID(ctx context.Context, r *http.Request, is_public bool)
|
|||
if err != nil {
|
||||
return nil, nhttp.NewError("get report: %w", err)
|
||||
}
|
||||
populateDistrictURI(&report.PublicReport, res.router)
|
||||
populateReportURI(&report.PublicReport, res.router, is_public)
|
||||
lint.LogOnErr(func() error {
|
||||
return populateDistrictURI(&report.PublicReport, res.router)
|
||||
}, "populate district URI")
|
||||
lint.LogOnErr(func() error {
|
||||
return populateReportURI(&report.PublicReport, res.router, is_public)
|
||||
}, "populate report URI")
|
||||
return report, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
//tablepublicreport "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/publicreport/table"
|
||||
//querypublicreport "github.com/Gleipnir-Technology/nidus-sync/db/query/publicreport"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/html"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/lint"
|
||||
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
|
||||
|
|
@ -149,7 +150,11 @@ func (res *waterR) byID(ctx context.Context, r *http.Request, is_public bool) (*
|
|||
if err != nil {
|
||||
return nil, nhttp.NewError("get report: %w", err)
|
||||
}
|
||||
populateDistrictURI(&report.PublicReport, res.router)
|
||||
populateReportURI(&report.PublicReport, res.router, is_public)
|
||||
lint.LogOnErr(func() error {
|
||||
return populateDistrictURI(&report.PublicReport, res.router)
|
||||
}, "populate district URI")
|
||||
lint.LogOnErr(func() error {
|
||||
return populateReportURI(&report.PublicReport, res.router, is_public)
|
||||
}, "populate report URI")
|
||||
return report, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue