Skip to content

Commit

Permalink
[db_functions] fail fast if error is expected
Browse files Browse the repository at this point in the history
  • Loading branch information
jbygdell committed Oct 22, 2024
1 parent f97c216 commit 440b590
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sda/internal/database/db_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"errors"
"math"
"strings"
"time"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -671,7 +672,7 @@ func (dbs *SDAdb) GetCorrID(user, path string) (string, error) {
// 2, 4, 8, 16, 32 seconds between each retry event.
for count := 1; count <= RetryTimes; count++ {
corrID, err = dbs.getCorrID(user, path)
if err == nil {
if err == nil || strings.Contains(err.Error(), "sql: no rows in result set") {
break
}
time.Sleep(time.Duration(math.Pow(2, float64(count))) * time.Second)
Expand Down Expand Up @@ -755,7 +756,7 @@ func (dbs *SDAdb) AddKeyHash(keyHash, keyDescription string) error {
// 2, 4, 8, 16, 32 seconds between each retry event.
for count := 1; count <= RetryTimes; count++ {
err = dbs.addKeyHash(keyHash, keyDescription)
if err == nil {
if err == nil || strings.Contains(err.Error(), "key hash already exists") {
break
}
time.Sleep(time.Duration(math.Pow(2, float64(count))) * time.Second)
Expand Down

0 comments on commit 440b590

Please sign in to comment.