You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to handle the case where a query returns no results using sqlx.NamedQueryContext. The expectation was that if no rows exist, it would return sql.ErrNoRows, allowing proper error handling.
What are the expected results?
If no rows are returned, NamedQueryContext should allow proper detection of this case in the error handling logic.
What are the received results?
Currently, NamedQueryContext does not return sql.ErrNoRows. Instead, it returns a valid *sqlx.Rows object with nil error. This means the following check will never trigger:
if err != nil {
if err == sql.ErrNoRows {
return bootstrap.Config{}, errors.Wrap(repoerr.ErrNotFound, err)
}
}
Instead, the correct way to check for no results is via row.Next():
if !row.Next() { // This will correctly detect no rows
return bootstrap.Config{}, errors.Wrap(repoerr.ErrNotFound, row.Err())
}
Steps To Reproduce
Execute a query with NamedQueryContext where no rows match.
Observe that err == nil, but row.Next() returns false.
The existing error check for sql.ErrNoRows never triggers, leading to incorrect error handling.
In what environment did you encounter the issue?
Go version: 1.23.4
Magistrala version/commit: main
Additional information you deem important
No response
The text was updated successfully, but these errors were encountered:
What were you trying to achieve?
I was trying to handle the case where a query returns no results using
sqlx.NamedQueryContext
. The expectation was that if no rows exist, it would returnsql.ErrNoRows
, allowing proper error handling.What are the expected results?
If no rows are returned,
NamedQueryContext
should allow proper detection of this case in the error handling logic.What are the received results?
Currently,
NamedQueryContext
does not returnsql.ErrNoRows
. Instead, it returns a valid*sqlx.Rows
object withnil
error. This means the following check will never trigger:Instead, the correct way to check for no results is via
row.Next()
:Steps To Reproduce
In what environment did you encounter the issue?
Go version: 1.23.4
Magistrala version/commit: main
Additional information you deem important
No response
The text was updated successfully, but these errors were encountered: