Skip to content

fix server not detecting conflicts on duplicated names #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion node-registrar/pkg/db/farms.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package db

import (
"strings"

"github.com/pkg/errors"
"gorm.io/gorm"
)
Expand Down Expand Up @@ -41,9 +43,10 @@ func (db *Database) GetFarm(farmID uint64) (farm Farm, err error) {

func (db *Database) CreateFarm(farm Farm) (uint64, error) {
if err := db.gormDB.Create(&farm).Error; err != nil {
if errors.Is(err, gorm.ErrDuplicatedKey) {
if errors.Is(err, gorm.ErrDuplicatedKey) || strings.Contains(err.Error(), "23505") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if checking on the error code would be better

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tried to match against pq.ErrorCode but it didn't work so I matched strings

return 0, ErrRecordAlreadyExists
}
return 0, err
}

return farm.FarmID, nil
Expand Down
Loading