fix: properly handle rows.Err() (#4261)
* fix (auth): properly handle rows.Err() * fix (auth/ldap): properly handle rows.Err() * fix (auth/oidc): properly handle rows.Err() * fix (auth/password): properly handle rows.Err() * fix (authtoken): properly handle rows.Err() * fix (credential): properly handle rows.Err() * fix (credential/static): properly handle rows.Err() * fix (credential/vault): properly handle rows.Err() * fix (db): properly handle rows.Err() * fix (db/schema): properly handle rows.Err() * fix (db/migrations): properly handle rows.Err() * fix (host): properly handle rows.Err() * fix (host/plugin): properly handle rows.Err() * fix (host/static): properly handle rows.Err() * fix (iam): properly handle rows.Err() * fix (kms): properly handle rows.Err() * fix (oplog): properly handle rows.Err() * fix (pagination/purge): properly handle rows.Err() * fix (plugin): properly handle rows.Err() * fix (job/scheduler): properly handle rows.Err() * fix (server): properly handle rows.Err() * fix (session): properly handle rows.Err() * fix (target): properly handle rows.Err()
This commit is contained in:
59 files changed
+252
-2
No files matched your search
@@ -39,6 +39,9 @@ Just some high-level usage highlights to get you started. Read the godocs for a
|
||||
}
|
||||
// Do something with the Gorm user struct
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
// do something with the err
|
||||
}
|
||||
|
||||
// DoTx is a writer function that wraps a TxHandler
|
||||
// in a retryable transaction. You simply implement a
|
||||
|
||||
@@ -510,6 +510,7 @@ func TestDomain_DefaultUsersExist(t *testing.T) {
|
||||
for rows.Next() {
|
||||
count++
|
||||
}
|
||||
assert.NoError(t, rows.Err())
|
||||
assert.Equal(t, 1, count)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -556,6 +556,9 @@ func (rw *Db) Now(ctx context.Context) (time.Time, error) {
|
||||
return time.Time{}, errors.Wrap(ctx, err, op, errors.WithMsg("failed to query current timestamp"))
|
||||
}
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return time.Time{}, errors.Wrap(ctx, err, op, errors.WithMsg("failed to query current timestamp"))
|
||||
}
|
||||
return now, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1642,6 +1642,7 @@ func TestDb_ScanRows(t *testing.T) {
|
||||
require.NoError(err)
|
||||
assert.Equal(user.PublicId, u.PublicId)
|
||||
}
|
||||
assert.NoError(rows.Err())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1672,6 +1673,7 @@ func TestDb_Query(t *testing.T) {
|
||||
require.NoError(err)
|
||||
assert.Equal(user.PublicId, u.PublicId)
|
||||
}
|
||||
assert.NoError(rows.Err())
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,9 @@ func ExampleManager_hooks() {
|
||||
}
|
||||
invalid = append(invalid, fmt.Sprintf("%d:%s", id, name))
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(invalid) > 0 {
|
||||
return append([]string{"invalid foos:"}, invalid...), nil
|
||||
@@ -116,6 +119,9 @@ func ExampleManager_hooks() {
|
||||
}
|
||||
invalid = append(invalid, fmt.Sprintf("%d:%s", id, name))
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(invalid) > 0 {
|
||||
return append([]string{"deleted foos:"}, invalid...), nil
|
||||
|
||||
@@ -90,6 +90,7 @@ func TestMigration(t *testing.T) {
|
||||
require.NoError(rows.Scan(&sessVal, &serverVal))
|
||||
require.False(serverVal.Valid)
|
||||
}
|
||||
require.NoError(rows.Err())
|
||||
|
||||
_, err = db.Query(update)
|
||||
require.NoError(err)
|
||||
@@ -104,4 +105,5 @@ func TestMigration(t *testing.T) {
|
||||
require.Equal(tests[count].sessServerId, serverVal.String)
|
||||
count++
|
||||
}
|
||||
require.NoError(rows.Err())
|
||||
}
|
||||
@@ -127,6 +127,7 @@ func Test_ServerEnumChanges(t *testing.T) {
|
||||
require.NoError(rows.Scan(&a))
|
||||
actualEnm = append(actualEnm, a)
|
||||
}
|
||||
require.NoError(rows.Err())
|
||||
require.Equal([]string{"controller", "worker"}, actualEnm)
|
||||
|
||||
// Try inserting a broken row
|
||||
|
||||
@@ -229,6 +229,7 @@ values
|
||||
require.NoError(t, rw.ScanRows(context.Background(), rows, &addr))
|
||||
results = append(results, addr)
|
||||
}
|
||||
assert.NoError(t, rows.Err())
|
||||
assert.ElementsMatch(t, results, addresses)
|
||||
}
|
||||
}
|
||||
@@ -251,6 +251,7 @@ func loadKeks(t *testing.T, rw *db.Db) []kek {
|
||||
require.NoError(t, rw.ScanRows(context.Background(), rows, &key))
|
||||
keks = append(keks, key)
|
||||
}
|
||||
require.NoError(t, rows.Err())
|
||||
return keks
|
||||
}
|
||||
|
||||
@@ -266,6 +267,7 @@ func loadKekVersions(t *testing.T, rw *db.Db) []kekVersion {
|
||||
require.NoError(t, rw.ScanRows(context.Background(), rows, &v))
|
||||
kekVersions = append(kekVersions, v)
|
||||
}
|
||||
require.NoError(t, rows.Err())
|
||||
return kekVersions
|
||||
}
|
||||
|
||||
@@ -281,6 +283,7 @@ func loadNewDeks(t *testing.T, rw *db.Db) []dek {
|
||||
require.NoError(t, rw.ScanRows(context.Background(), rows, &key))
|
||||
deks = append(deks, key)
|
||||
}
|
||||
require.NoError(t, rows.Err())
|
||||
return deks
|
||||
}
|
||||
|
||||
@@ -315,6 +318,7 @@ func loadCurrentDeks(t *testing.T, rw *db.Db) []dek {
|
||||
require.NoError(t, rw.ScanRows(context.Background(), rows, &key))
|
||||
deks = append(deks, key)
|
||||
}
|
||||
require.NoError(t, rows.Err())
|
||||
}
|
||||
return deks
|
||||
}
|
||||
@@ -331,6 +335,7 @@ func loadNewDekVersions(t *testing.T, rw *db.Db) []dekVersion {
|
||||
require.NoError(t, rw.ScanRows(context.Background(), rows, &v))
|
||||
dekVersions = append(dekVersions, v)
|
||||
}
|
||||
require.NoError(t, rows.Err())
|
||||
return dekVersions
|
||||
}
|
||||
|
||||
@@ -420,6 +425,7 @@ func loadCurrentDekVersions(t *testing.T, rw *db.Db) []dekVersion {
|
||||
}
|
||||
dekVersions = append(dekVersions, v)
|
||||
}
|
||||
require.NoError(t, rows.Err())
|
||||
}
|
||||
return dekVersions
|
||||
}
|
||||
|
||||
@@ -371,6 +371,7 @@ func validateRepairFunc(t *testing.T, rw *db.Db, repairReport migration.Repairs)
|
||||
resourceId: resourceId,
|
||||
})
|
||||
}
|
||||
require.NoError(rows.Err())
|
||||
require.Equal([]targetAssociation{
|
||||
{
|
||||
targetId: "ttcp_PRJA___65001",
|
||||
|
||||
@@ -53,7 +53,9 @@ func TestMigrationHook8202(t *testing.T) {
|
||||
require.NoError(t, rows.Scan(&targetOrgId))
|
||||
count++
|
||||
}
|
||||
require.NoError(t, rows.Err())
|
||||
rows.Close()
|
||||
require.NoError(t, rows.Err())
|
||||
assert.Equal(t, 1, count)
|
||||
assert.Equal(t, "o_test__82002", *targetOrgId)
|
||||
|
||||
@@ -66,6 +68,7 @@ func TestMigrationHook8202(t *testing.T) {
|
||||
require.NoError(t, rows.Scan(&targetOrgId))
|
||||
count++
|
||||
}
|
||||
require.NoError(t, rows.Err())
|
||||
assert.Equal(t, 1, count)
|
||||
assert.Nil(t, targetOrgId)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user