Skip to content

Commit 7bb2494

Browse files
committed
fix: unique constraint check error silently
1 parent 6b74cba commit 7bb2494

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

universalClient/chains/common/chain_store.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package common
22

33
import (
44
"fmt"
5+
"strings"
56

67
"gorm.io/gorm"
78

@@ -211,6 +212,11 @@ func (cs *ChainStore) InsertEventIfNotExists(event *store.Event) (bool, error) {
211212

212213
// Store new event
213214
if err := cs.database.Client().Create(event).Error; err != nil {
215+
// UNIQUE constraint violation means another goroutine or poll cycle already
216+
// inserted this event between our check and insert — treat as duplicate.
217+
if strings.Contains(err.Error(), "UNIQUE constraint failed") {
218+
return false, nil
219+
}
214220
return false, fmt.Errorf("failed to create event: %w", err)
215221
}
216222

0 commit comments

Comments
 (0)