Skip to content

Commit

Permalink
PR Feedback for #647 - Error out when both params set
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Ramage committed Nov 4, 2021
1 parent 18dd02b commit b63f099
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions database/mongodb/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const contextWaitTimeout = 5 * time.Second // how long to wait for

var (
ErrNoDatabaseName = fmt.Errorf("no database name")
ErrNilConfig = fmt.Errorf("no config")
ErrNilConfig = fmt.Errorf("no config")
ErrTypoAndNotNonTypoUsed = fmt.Errorf("both x-advisory-lock-timeout-interval and x-advisory-lock-timout-interval were specified")
)

type Mongo struct {
Expand Down Expand Up @@ -138,11 +139,17 @@ func (m *Mongo) Open(dsn string) (database.Driver, error) {
return nil, err
}

lockTimeout := unknown.Get("x-advisory-lock-timeout-interval")
lockTimeoutIntervalValue := unknown.Get("x-advisory-lock-timeout-interval")
// The initial release had a typo for this argument but for backwards compatibility sake, we will keep supporting it
// and we will error out if both values are set.
lockTimeoutIntervalValueFromTypo := unknown.Get("x-advisory-lock-timout-interval")

if lockTimeout == "" {
// The initial release had a typo for this argument but for backwards compatibility sake, we will keep supporting it.
lockTimeout = unknown.Get("x-advisory-lock-timout-interval")
lockTimeout := lockTimeoutIntervalValue

if (lockTimeoutIntervalValue != "" && lockTimeoutIntervalValueFromTypo != "") {
return nil, ErrTypoAndNotNonTypoUsed
} else if (lockTimeoutIntervalValueFromTypo != "") {
lockTimeout = lockTimeoutIntervalValueFromTypo
}

maxLockCheckInterval, err := parseInt(lockTimeout, DefaultLockTimeoutInterval)
Expand Down

0 comments on commit b63f099

Please sign in to comment.