diff --git a/archives/archives.go b/archives/archives.go index a7c65f9..5a22cb2 100644 --- a/archives/archives.go +++ b/archives/archives.go @@ -19,7 +19,6 @@ import ( "github.com/lib/pq" "github.com/nyaruka/gocommon/analytics" "github.com/nyaruka/gocommon/dates" - "github.com/pkg/errors" ) // ArchiveType is the type for the archives @@ -104,7 +103,7 @@ func GetActiveOrgs(ctx context.Context, db *sqlx.DB, conf *Config) ([]Org, error rows, err := db.QueryxContext(ctx, sqlLookupActiveOrgs) if err != nil { - return nil, errors.Wrapf(err, "error fetching active orgs") + return nil, fmt.Errorf("error fetching active orgs: %w", err) } defer rows.Close() @@ -113,7 +112,7 @@ func GetActiveOrgs(ctx context.Context, db *sqlx.DB, conf *Config) ([]Org, error org := Org{RetentionPeriod: conf.RetentionPeriod} err = rows.StructScan(&org) if err != nil { - return nil, errors.Wrapf(err, "error scanning active org") + return nil, fmt.Errorf("error scanning active org: %w", err) } orgs = append(orgs, org) } @@ -135,7 +134,7 @@ func GetCurrentArchives(ctx context.Context, db *sqlx.DB, org Org, archiveType A archives := make([]*Archive, 0, 1) err := db.SelectContext(ctx, &archives, sqlLookupOrgArchives, org.ID, archiveType) if err != nil && err != sql.ErrNoRows { - return nil, errors.Wrapf(err, "error selecting current archives for org: %d and type: %s", org.ID, archiveType) + return nil, fmt.Errorf("error selecting current archives for org: %d and type: %s: %w", org.ID, archiveType, err) } return archives, nil @@ -155,7 +154,7 @@ func GetArchivesNeedingDeletion(ctx context.Context, db *sqlx.DB, org Org, archi archives := make([]*Archive, 0, 1) err := db.SelectContext(ctx, &archives, sqlLookupArchivesNeedingDeletion, org.ID, archiveType) if err != nil && err != sql.ErrNoRows { - return nil, errors.Wrapf(err, "error selecting archives needing deletion for org: %d and type: %s", org.ID, archiveType) + return nil, fmt.Errorf("error selecting archives needing deletion for org: %d and type: %s: %w", org.ID, archiveType, err) } return archives, nil @@ -175,7 +174,7 @@ func GetCurrentArchiveCount(ctx context.Context, db *sqlx.DB, org Org, archiveTy err := db.GetContext(ctx, &archiveCount, sqlCountOrgArchives, org.ID, archiveType) if err != nil { - return 0, errors.Wrapf(err, "error querying archive count for org: %d and type: %s", org.ID, archiveType) + return 0, fmt.Errorf("error querying archive count for org: %d and type: %s: %w", org.ID, archiveType, err) } return archiveCount, nil @@ -197,7 +196,7 @@ func GetDailyArchivesForDateRange(ctx context.Context, db *sqlx.DB, org Org, arc err := db.SelectContext(ctx, &existingArchives, sqlLookupOrgDailyArchivesForDateRange, org.ID, archiveType, DayPeriod, startDate, endDate) if err != nil && err != sql.ErrNoRows { - return nil, errors.Wrapf(err, "error selecting daily archives for org: %d and type: %s", org.ID, archiveType) + return nil, fmt.Errorf("error selecting daily archives for org: %d and type: %s: %w", org.ID, archiveType, err) } return existingArchives, nil @@ -241,7 +240,7 @@ func GetMissingDailyArchivesForDateRange(ctx context.Context, db *sqlx.DB, start rows, err := db.QueryxContext(ctx, sqlLookupMissingDailyArchive, startDate, endDate, org.ID, DayPeriod, archiveType) if err != nil { - return nil, errors.Wrapf(err, "error getting missing daily archives for org: %d and type: %s", org.ID, archiveType) + return nil, fmt.Errorf("error getting missing daily archives for org: %d and type: %s: %w", org.ID, archiveType, err) } defer rows.Close() @@ -250,7 +249,7 @@ func GetMissingDailyArchivesForDateRange(ctx context.Context, db *sqlx.DB, start err = rows.Scan(&missingDay) if err != nil { - return nil, errors.Wrapf(err, "error scanning missing daily archive for org: %d and type: %s", org.ID, archiveType) + return nil, fmt.Errorf("error scanning missing daily archive for org: %d and type: %s: %w", org.ID, archiveType, err) } archive := Archive{ Org: org, @@ -295,7 +294,7 @@ func GetMissingMonthlyArchives(ctx context.Context, db *sqlx.DB, now time.Time, rows, err := db.QueryxContext(ctx, sqlLookupMissingMonthlyArchive, startDate, endDate, org.ID, MonthPeriod, archiveType) if err != nil { - return nil, errors.Wrapf(err, "error getting missing monthly archive for org: %d and type: %s", org.ID, archiveType) + return nil, fmt.Errorf("error getting missing monthly archive for org: %d and type: %s: %w", org.ID, archiveType, err) } defer rows.Close() @@ -304,7 +303,7 @@ func GetMissingMonthlyArchives(ctx context.Context, db *sqlx.DB, now time.Time, err = rows.Scan(&missingMonth) if err != nil { - return nil, errors.Wrapf(err, "error scanning missing monthly archive for org: %d and type: %s", org.ID, archiveType) + return nil, fmt.Errorf("error scanning missing monthly archive for org: %d and type: %s: %w", org.ID, archiveType, err) } archive := Archive{ Org: org, @@ -349,7 +348,7 @@ func BuildRollupArchive(ctx context.Context, db *sqlx.DB, conf *Config, s3Client filename := fmt.Sprintf("%s_%d_%s_%d_%02d_", monthlyArchive.ArchiveType, monthlyArchive.Org.ID, monthlyArchive.Period, monthlyArchive.StartDate.Year(), monthlyArchive.StartDate.Month()) file, err := os.CreateTemp(conf.TempDir, filename) if err != nil { - return errors.Wrapf(err, "error creating temp file: %s", filename) + return fmt.Errorf("error creating temp file: %s: %w", filename, err) } writerHash := md5.New() gzWriter := gzip.NewWriter(io.MultiWriter(file, writerHash)) @@ -378,7 +377,7 @@ func BuildRollupArchive(ctx context.Context, db *sqlx.DB, conf *Config, s3Client reader, err := GetS3File(ctx, s3Client, daily.URL) if err != nil { - return errors.Wrapf(err, "error reading S3 URL: %s", daily.URL) + return fmt.Errorf("error reading S3 URL: %s: %w", daily.URL, err) } // set up our reader to calculate our hash along the way @@ -386,13 +385,13 @@ func BuildRollupArchive(ctx context.Context, db *sqlx.DB, conf *Config, s3Client teeReader := io.TeeReader(reader, readerHash) gzipReader, err := gzip.NewReader(teeReader) if err != nil { - return errors.Wrapf(err, "error creating gzip reader") + return fmt.Errorf("error creating gzip reader: %w", err) } // copy this daily file (uncompressed) to our new monthly file _, err = io.Copy(writer, gzipReader) if err != nil { - return errors.Wrapf(err, "error copying from s3 to disk for URL: %s", daily.URL) + return fmt.Errorf("error copying from s3 to disk for URL: %s: %w", daily.URL, err) } reader.Close() @@ -422,7 +421,7 @@ func BuildRollupArchive(ctx context.Context, db *sqlx.DB, conf *Config, s3Client monthlyArchive.Hash = hex.EncodeToString(writerHash.Sum(nil)) stat, err := file.Stat() if err != nil { - return errors.Wrapf(err, "error statting file: %s", file.Name()) + return fmt.Errorf("error statting file: %s: %w", file.Name(), err) } monthlyArchive.Size = stat.Size() monthlyArchive.RecordCount = recordCount @@ -444,7 +443,7 @@ func EnsureTempArchiveDirectory(path string) error { if os.IsNotExist(err) { return os.MkdirAll(path, 0700) } else if err != nil { - return errors.Wrapf(err, "error statting temp dir: %s", path) + return fmt.Errorf("error statting temp dir: %s: %w", path, err) } // is path a directory @@ -482,7 +481,7 @@ func CreateArchiveFile(ctx context.Context, db *sqlx.DB, archive *Archive, archi filename := fmt.Sprintf("%s_%d_%s%d%02d%02d_", archive.ArchiveType, archive.Org.ID, archive.Period, archive.StartDate.Year(), archive.StartDate.Month(), archive.StartDate.Day()) file, err := os.CreateTemp(archivePath, filename) if err != nil { - return errors.Wrapf(err, "error creating temp file: %s", filename) + return fmt.Errorf("error creating temp file: %s: %w", filename, err) } defer func() { @@ -513,24 +512,24 @@ func CreateArchiveFile(ctx context.Context, db *sqlx.DB, archive *Archive, archi } if err != nil { - return errors.Wrapf(err, "error writing archive") + return fmt.Errorf("error writing archive: %w", err) } err = writer.Flush() if err != nil { - return errors.Wrapf(err, "error flushing archive file") + return fmt.Errorf("error flushing archive file: %w", err) } err = gzWriter.Close() if err != nil { - return errors.Wrapf(err, "error closing archive gzip writer") + return fmt.Errorf("error closing archive gzip writer: %w", err) } // calculate our size and hash archive.Hash = hex.EncodeToString(hash.Sum(nil)) stat, err := file.Stat() if err != nil { - return errors.Wrapf(err, "error calculating archive hash") + return fmt.Errorf("error calculating archive hash: %w", err) } archive.ArchiveFile = file.Name() @@ -571,7 +570,7 @@ func UploadArchive(ctx context.Context, s3Client s3iface.S3API, bucket string, a err := UploadToS3(ctx, s3Client, bucket, archivePath, archive) if err != nil { - return errors.Wrapf(err, "error uploading archive to S3") + return fmt.Errorf("error uploading archive to S3: %w", err) } archive.NeedsDeletion = true @@ -603,20 +602,20 @@ func WriteArchiveToDB(ctx context.Context, db *sqlx.DB, archive *Archive) error tx, err := db.BeginTxx(ctx, nil) if err != nil { - return errors.Wrapf(err, "error starting transaction") + return fmt.Errorf("error starting transaction: %w", err) } rows, err := tx.NamedQuery(sqlInsertArchive, archive) if err != nil { tx.Rollback() - return errors.Wrapf(err, "error inserting archive") + return fmt.Errorf("error inserting archive: %w", err) } rows.Next() err = rows.Scan(&archive.ID) if err != nil { tx.Rollback() - return errors.Wrapf(err, "error reading new archive id") + return fmt.Errorf("error reading new archive id: %w", err) } rows.Close() @@ -631,12 +630,12 @@ func WriteArchiveToDB(ctx context.Context, db *sqlx.DB, archive *Archive) error result, err := tx.ExecContext(ctx, `UPDATE archives_archive SET rollup_id = $1 WHERE id = ANY($2)`, archive.ID, pq.Array(childIDs)) if err != nil { tx.Rollback() - return errors.Wrapf(err, "error updating rollup ids") + return fmt.Errorf("error updating rollup ids: %w", err) } affected, err := result.RowsAffected() if err != nil { tx.Rollback() - return errors.Wrapf(err, "error getting number of rollup ids updated") + return fmt.Errorf("error getting number of rollup ids updated: %w", err) } if int(affected) != len(childIDs) { tx.Rollback() @@ -647,7 +646,7 @@ func WriteArchiveToDB(ctx context.Context, db *sqlx.DB, archive *Archive) error err = tx.Commit() if err != nil { tx.Rollback() - return errors.Wrapf(err, "error committing new archive transaction") + return fmt.Errorf("error committing new archive transaction: %w", err) } return nil } @@ -661,7 +660,7 @@ func DeleteArchiveFile(archive *Archive) error { err := os.Remove(archive.ArchiveFile) if err != nil { - return errors.Wrapf(err, "error deleting temp archive file: %s", archive.ArchiveFile) + return fmt.Errorf("error deleting temp archive file: %s: %w", archive.ArchiveFile, err) } slog.Debug("deleted temporary archive file", @@ -679,7 +678,7 @@ func DeleteArchiveFile(archive *Archive) error { func CreateOrgArchives(ctx context.Context, now time.Time, config *Config, db *sqlx.DB, s3Client s3iface.S3API, org Org, archiveType ArchiveType) ([]*Archive, []*Archive, []*Archive, []*Archive, error) { archiveCount, err := GetCurrentArchiveCount(ctx, db, org, archiveType) if err != nil { - return nil, nil, nil, nil, errors.Wrapf(err, "error getting current archive count") + return nil, nil, nil, nil, fmt.Errorf("error getting current archive count: %w", err) } var dailiesCreated, dailiesFailed, monthliesCreated, monthliesFailed []*Archive @@ -688,7 +687,7 @@ func CreateOrgArchives(ctx context.Context, now time.Time, config *Config, db *s if archiveCount == 0 { archives, err := GetMissingMonthlyArchives(ctx, db, now, org, archiveType) if err != nil { - return nil, nil, nil, nil, errors.Wrapf(err, "error getting missing monthly archives") + return nil, nil, nil, nil, fmt.Errorf("error getting missing monthly archives: %w", err) } // we first create monthly archives @@ -698,7 +697,7 @@ func CreateOrgArchives(ctx context.Context, now time.Time, config *Config, db *s // then add in daily archives taking into account the monthly that have been built daily, err := GetMissingDailyArchives(ctx, db, now, org, archiveType) if err != nil { - return nil, nil, nil, nil, errors.Wrapf(err, "error getting missing daily archives") + return nil, nil, nil, nil, fmt.Errorf("error getting missing daily archives: %w", err) } // we then create missing daily archives @@ -712,7 +711,7 @@ func CreateOrgArchives(ctx context.Context, now time.Time, config *Config, db *s func createArchive(ctx context.Context, db *sqlx.DB, config *Config, s3Client s3iface.S3API, archive *Archive) error { err := CreateArchiveFile(ctx, db, archive, config.TempDir) if err != nil { - return errors.Wrap(err, "error writing archive file") + return fmt.Errorf("error writing archive file: %w", err) } defer func() { @@ -727,13 +726,13 @@ func createArchive(ctx context.Context, db *sqlx.DB, config *Config, s3Client s3 if config.UploadToS3 { err = UploadArchive(ctx, s3Client, config.S3Bucket, archive) if err != nil { - return errors.Wrap(err, "error writing archive to s3") + return fmt.Errorf("error writing archive to s3: %w", err) } } err = WriteArchiveToDB(ctx, db, archive) if err != nil { - return errors.Wrap(err, "error writing record to db") + return fmt.Errorf("error writing record to db: %w", err) } return nil @@ -883,7 +882,7 @@ func ArchiveOrg(ctx context.Context, now time.Time, cfg *Config, db *sqlx.DB, s3 dailiesCreated, dailiesFailed, monthliesCreated, monthliesFailed, err := CreateOrgArchives(ctx, now, cfg, db, s3Client, org, archiveType) if err != nil { - return nil, nil, nil, nil, nil, errors.Wrapf(err, "error creating archives") + return nil, nil, nil, nil, nil, fmt.Errorf("error creating archives: %w", err) } if len(dailiesCreated) > 0 { @@ -894,7 +893,7 @@ func ArchiveOrg(ctx context.Context, now time.Time, cfg *Config, db *sqlx.DB, s3 rollupsCreated, rollupsFailed, err := RollupOrgArchives(ctx, now, cfg, db, s3Client, org, archiveType) if err != nil { - return nil, nil, nil, nil, nil, errors.Wrapf(err, "error rolling up archives") + return nil, nil, nil, nil, nil, fmt.Errorf("error rolling up archives: %w", err) } monthliesCreated = append(monthliesCreated, rollupsCreated...) @@ -906,7 +905,7 @@ func ArchiveOrg(ctx context.Context, now time.Time, cfg *Config, db *sqlx.DB, s3 if cfg.Delete { deleted, err = DeleteArchivedOrgRecords(ctx, now, cfg, db, s3Client, org, archiveType) if err != nil { - return dailiesCreated, dailiesFailed, monthliesCreated, monthliesFailed, nil, errors.Wrapf(err, "error deleting archived records") + return dailiesCreated, dailiesFailed, monthliesCreated, monthliesFailed, nil, fmt.Errorf("error deleting archived records: %w", err) } } @@ -923,7 +922,7 @@ func ArchiveActiveOrgs(db *sqlx.DB, cfg *Config, s3Client s3iface.S3API) error { cancel() if err != nil { - return errors.Wrap(err, "error getting active orgs") + return fmt.Errorf("error getting active orgs: %w", err) } totalRunsRecordsArchived, totalMsgsRecordsArchived := 0, 0 diff --git a/archives/messages.go b/archives/messages.go index 647b211..f7362ca 100644 --- a/archives/messages.go +++ b/archives/messages.go @@ -10,7 +10,6 @@ import ( "github.com/aws/aws-sdk-go/service/s3/s3iface" "github.com/jmoiron/sqlx" "github.com/nyaruka/gocommon/dates" - "github.com/pkg/errors" ) const ( @@ -75,14 +74,14 @@ func writeMessageRecords(ctx context.Context, db *sqlx.DB, archive *Archive, wri rows, err := db.QueryxContext(ctx, sqlLookupMsgs, archive.Org.ID, archive.StartDate, archive.endDate()) if err != nil { - return 0, errors.Wrapf(err, "error querying messages for org: %d", archive.Org.ID) + return 0, fmt.Errorf("error querying messages for org: %d: %w", archive.Org.ID, err) } defer rows.Close() for rows.Next() { err = rows.Scan(&visibility, &record) if err != nil { - return 0, errors.Wrapf(err, "error scanning message row for org: %d", archive.Org.ID) + return 0, fmt.Errorf("error scanning message row for org: %d: %w", archive.Org.ID, err) } if visibility == "deleted" { @@ -193,19 +192,19 @@ func DeleteArchivedMessages(ctx context.Context, config *Config, db *sqlx.DB, s3 // first delete any labelings err = executeInQuery(ctx, tx, sqlDeleteMessageLabels, idBatch) if err != nil { - return errors.Wrap(err, "error removing message labels") + return fmt.Errorf("error removing message labels: %w", err) } // then delete the messages themselves err = executeInQuery(ctx, tx, sqlDeleteMessages, idBatch) if err != nil { - return errors.Wrap(err, "error deleting messages") + return fmt.Errorf("error deleting messages: %w", err) } // commit our transaction err = tx.Commit() if err != nil { - return errors.Wrap(err, "error committing message delete transaction") + return fmt.Errorf("error committing message delete transaction: %w", err) } log.Debug("deleted batch of messages", "elapsed", dates.Since(start), "count", len(idBatch)) @@ -221,7 +220,7 @@ func DeleteArchivedMessages(ctx context.Context, config *Config, db *sqlx.DB, s3 // all went well! mark our archive as no longer needing deletion _, err = db.ExecContext(outer, sqlUpdateArchiveDeleted, archive.ID, deletedOn) if err != nil { - return errors.Wrap(err, "error setting archive as deleted") + return fmt.Errorf("error setting archive as deleted: %w", err) } archive.NeedsDeletion = false archive.DeletedOn = &deletedOn @@ -262,46 +261,46 @@ func DeleteBroadcasts(ctx context.Context, now time.Time, config *Config, db *sq var broadcastID int64 if err := rows.Scan(&broadcastID); err != nil { - return errors.Wrap(err, "unable to get broadcast id") + return fmt.Errorf("unable to get broadcast id: %w", err) } // we delete broadcasts in a transaction per broadcast tx, err := db.BeginTx(ctx, nil) if err != nil { - return errors.Wrapf(err, "error starting transaction while deleting broadcast: %d", broadcastID) + return fmt.Errorf("error starting transaction while deleting broadcast: %d: %w", broadcastID, err) } // delete contacts M2M _, err = tx.Exec(`DELETE from msgs_broadcast_contacts WHERE broadcast_id = $1`, broadcastID) if err != nil { tx.Rollback() - return errors.Wrapf(err, "error deleting related contacts for broadcast: %d", broadcastID) + return fmt.Errorf("error deleting related contacts for broadcast: %d: %w", broadcastID, err) } // delete groups M2M _, err = tx.Exec(`DELETE from msgs_broadcast_groups WHERE broadcast_id = $1`, broadcastID) if err != nil { tx.Rollback() - return errors.Wrapf(err, "error deleting related groups for broadcast: %d", broadcastID) + return fmt.Errorf("error deleting related groups for broadcast: %d: %w", broadcastID, err) } // delete counts associated with this broadcast _, err = tx.Exec(`DELETE from msgs_broadcastmsgcount WHERE broadcast_id = $1`, broadcastID) if err != nil { tx.Rollback() - return errors.Wrapf(err, "error deleting counts for broadcast: %d", broadcastID) + return fmt.Errorf("error deleting counts for broadcast: %d: %w", broadcastID, err) } // finally, delete our broadcast _, err = tx.Exec(`DELETE from msgs_broadcast WHERE id = $1`, broadcastID) if err != nil { tx.Rollback() - return errors.Wrapf(err, "error deleting broadcast: %d", broadcastID) + return fmt.Errorf("error deleting broadcast: %d: %w", broadcastID, err) } err = tx.Commit() if err != nil { - return errors.Wrapf(err, "error deleting broadcast: %d", broadcastID) + return fmt.Errorf("error deleting broadcast: %d: %w", broadcastID, err) } count++ diff --git a/archives/runs.go b/archives/runs.go index b9ea8e7..d713322 100644 --- a/archives/runs.go +++ b/archives/runs.go @@ -10,7 +10,6 @@ import ( "github.com/aws/aws-sdk-go/service/s3/s3iface" "github.com/jmoiron/sqlx" "github.com/nyaruka/gocommon/dates" - "github.com/pkg/errors" ) const ( @@ -62,7 +61,7 @@ func writeRunRecords(ctx context.Context, db *sqlx.DB, archive *Archive, writer var rows *sqlx.Rows rows, err := db.QueryxContext(ctx, sqlLookupRuns, archive.Org.ID, archive.StartDate, archive.endDate()) if err != nil { - return 0, errors.Wrapf(err, "error querying run records for org: %d", archive.Org.ID) + return 0, fmt.Errorf("error querying run records for org: %d: %w", archive.Org.ID, err) } defer rows.Close() @@ -76,7 +75,7 @@ func writeRunRecords(ctx context.Context, db *sqlx.DB, archive *Archive, writer err = rows.Scan(&runUUID, &runExitedOn, &record) if err != nil { - return 0, errors.Wrapf(err, "error scanning run record for org: %d", archive.Org.ID) + return 0, fmt.Errorf("error scanning run record for org: %d: %w", archive.Org.ID, err) } // shouldn't be archiving an active run, that's an error @@ -188,13 +187,13 @@ func DeleteArchivedRuns(ctx context.Context, config *Config, db *sqlx.DB, s3Clie // delete our runs err = executeInQuery(ctx, tx, sqlDeleteRuns, idBatch) if err != nil { - return errors.Wrap(err, "error deleting runs") + return fmt.Errorf("error deleting runs: %w", err) } // commit our transaction err = tx.Commit() if err != nil { - return errors.Wrap(err, "error committing run delete transaction") + return fmt.Errorf("error committing run delete transaction: %w", err) } log.Debug("deleted batch of runs", "elapsed", dates.Since(start), "count", len(idBatch)) @@ -210,7 +209,7 @@ func DeleteArchivedRuns(ctx context.Context, config *Config, db *sqlx.DB, s3Clie // all went well! mark our archive as no longer needing deletion _, err = db.ExecContext(outer, sqlUpdateArchiveDeleted, archive.ID, deletedOn) if err != nil { - return errors.Wrap(err, "error setting archive as deleted") + return fmt.Errorf("error setting archive as deleted: %w", err) } archive.NeedsDeletion = false archive.DeletedOn = &deletedOn @@ -250,53 +249,53 @@ func DeleteFlowStarts(ctx context.Context, now time.Time, config *Config, db *sq var startID int64 if err := rows.Scan(&startID); err != nil { - return errors.Wrap(err, "unable to get start id") + return fmt.Errorf("unable to get start id: %w", err) } // we delete starts in a transaction per start tx, err := db.BeginTx(ctx, nil) if err != nil { - return errors.Wrapf(err, "error starting transaction while deleting start: %d", startID) + return fmt.Errorf("error starting transaction while deleting start: %d: %w", startID, err) } // delete contacts M2M _, err = tx.Exec(`DELETE from flows_flowstart_contacts WHERE flowstart_id = $1`, startID) if err != nil { tx.Rollback() - return errors.Wrapf(err, "error deleting related contacts for start: %d", startID) + return fmt.Errorf("error deleting related contacts for start: %d: %w", startID, err) } // delete groups M2M _, err = tx.Exec(`DELETE from flows_flowstart_groups WHERE flowstart_id = $1`, startID) if err != nil { tx.Rollback() - return errors.Wrapf(err, "error deleting related groups for start: %d", startID) + return fmt.Errorf("error deleting related groups for start: %d: %w", startID, err) } // delete calls M2M _, err = tx.Exec(`DELETE from flows_flowstart_calls WHERE flowstart_id = $1`, startID) if err != nil { tx.Rollback() - return errors.Wrapf(err, "error deleting related calls for start: %d", startID) + return fmt.Errorf("error deleting related calls for start: %d: %w", startID, err) } // delete counts _, err = tx.Exec(`DELETE from flows_flowstartcount WHERE start_id = $1`, startID) if err != nil { tx.Rollback() - return errors.Wrapf(err, "error deleting counts for start: %d", startID) + return fmt.Errorf("error deleting counts for start: %d: %w", startID, err) } // finally, delete our start _, err = tx.Exec(`DELETE from flows_flowstart WHERE id = $1`, startID) if err != nil { tx.Rollback() - return errors.Wrapf(err, "error deleting start: %d", startID) + return fmt.Errorf("error deleting start: %d: %w", startID, err) } err = tx.Commit() if err != nil { - return errors.Wrapf(err, "error deleting start: %d", startID) + return fmt.Errorf("error deleting start: %d: %w", startID, err) } count++ diff --git a/go.mod b/go.mod index e3002cb..8e3c60c 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,6 @@ require ( github.com/lib/pq v1.10.9 github.com/nyaruka/ezconf v0.3.0 github.com/nyaruka/gocommon v1.53.2 - github.com/pkg/errors v0.9.1 github.com/samber/slog-multi v1.0.2 github.com/samber/slog-sentry v1.2.2 github.com/stretchr/testify v1.9.0 @@ -25,6 +24,7 @@ require ( github.com/nyaruka/librato v1.1.1 // indirect github.com/nyaruka/null/v2 v2.0.3 // indirect github.com/nyaruka/phonenumbers v1.3.4 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/samber/lo v1.38.1 // indirect golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect