Skip to content

Commit

Permalink
Fix NamedQueryContext not returning sql.ErrNoRows
Browse files Browse the repository at this point in the history
  • Loading branch information
nnpvaan committed Feb 26, 2025
1 parent 9c15ba6 commit e26cbf4
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions bootstrap/postgres/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,11 @@ func (cr configRepository) RetrieveByID(ctx context.Context, domainID, id string
}
row, err := cr.db.NamedQueryContext(ctx, q, dbcfg)
if err != nil {
if err == sql.ErrNoRows {
return bootstrap.Config{}, errors.Wrap(repoerr.ErrNotFound, err)
}

return bootstrap.Config{}, errors.Wrap(repoerr.ErrViewEntity, err)
}

if ok := row.Next(); !ok {
return bootstrap.Config{}, errors.Wrap(repoerr.ErrNotFound, row.Err())
if !row.Next() {
return bootstrap.Config{}, errors.Wrap(repoerr.ErrNotFound, sql.ErrNoRows)
}

if err := row.StructScan(&dbcfg); err != nil {
Expand Down Expand Up @@ -211,8 +207,8 @@ func (cr configRepository) RetrieveByExternalID(ctx context.Context, externalID
return bootstrap.Config{}, errors.Wrap(repoerr.ErrViewEntity, err)
}

if ok := row.Next(); !ok {
return bootstrap.Config{}, errors.Wrap(repoerr.ErrNotFound, row.Err())
if !row.Next() {
return bootstrap.Config{}, errors.Wrap(repoerr.ErrNotFound, sql.ErrNoRows)
}

if err := row.StructScan(&dbcfg); err != nil {
Expand Down

0 comments on commit e26cbf4

Please sign in to comment.