Skip to content

Commit

Permalink
fix(blobstorage): specifying duplication error by number and not by g…
Browse files Browse the repository at this point in the history
…orm error type
  • Loading branch information
k-kaddal committed May 1, 2024
1 parent a219676 commit a9c542f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/blobstorage/pkg/repo/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"log/slog"

"github.com/go-sql-driver/mysql"
blobstorage "github.com/taikoxyz/taiko-mono/packages/blobstorage"
"gorm.io/gorm"
)
Expand Down Expand Up @@ -59,7 +60,8 @@ func (r *Repositories) SaveBlobAndBlockMeta(
saveBlobHashOpts.BlobData,
)
if err != nil {
if errors.Is(err, gorm.ErrDuplicatedKey) {
var mysqlErr *mysql.MySQLError
if errors.As(err, &mysqlErr) && mysqlErr.Number == 1062 {
slog.Warn("Duplicate entry for blob, continuing", "blobHash", saveBlobHashOpts.BlobHash)
return nil
}
Expand All @@ -79,6 +81,11 @@ func (r *Repositories) SaveBlobAndBlockMeta(
saveBlockMetaOpts.EmittedBlockID,
)
if err != nil {
var mysqlErr *mysql.MySQLError
if errors.As(err, &mysqlErr) && mysqlErr.Number == 1062 {
slog.Warn("Duplicate entry for block_meta, continuing", "blockId", saveBlockMetaOpts.BlockID)
return nil
}
slog.Error("Error storing blockMeta in DB", "error", err)
return err
}
Expand Down

0 comments on commit a9c542f

Please sign in to comment.