From 91545957e1f3d13029e02963ec512c6e616e2040 Mon Sep 17 00:00:00 2001 From: nnpvaan Date: Wed, 26 Feb 2025 17:51:08 +0700 Subject: [PATCH] Fix NamedQueryContext not returning sql.ErrNoRows --- bootstrap/postgres/configs.go | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/bootstrap/postgres/configs.go b/bootstrap/postgres/configs.go index 73b3130b1..3b6a5aa86 100644 --- a/bootstrap/postgres/configs.go +++ b/bootstrap/postgres/configs.go @@ -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 { @@ -205,14 +201,11 @@ func (cr configRepository) RetrieveByExternalID(ctx context.Context, externalID 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 {