diff --git a/rows.go b/rows.go index cdd72a25..055a6645 100644 --- a/rows.go +++ b/rows.go @@ -231,7 +231,11 @@ func (rows *baseRows) Scan(dest ...any) error { if len(dest) == 1 { if rc, ok := dest[0].(RowScanner); ok { - return rc.ScanRow(rows) + err := rc.ScanRow(rows) + if err != nil { + rows.fatal(err) + } + return err } } diff --git a/rows_test.go b/rows_test.go index 3bc587a7..1699d408 100644 --- a/rows_test.go +++ b/rows_test.go @@ -36,6 +36,22 @@ func TestRowScanner(t *testing.T) { }) } +type testErrRowScanner string + +func (ers *testErrRowScanner) ScanRow(rows pgx.Rows) error { + return errors.New(string(*ers)) +} + +func TestRowScannerErrorIsFatalToRows(t *testing.T) { + t.Parallel() + + defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { + s := testErrRowScanner("foo") + err := conn.QueryRow(ctx, "select 'Adam' as name, 72 as height").Scan(&s) + require.EqualError(t, err, "foo") + }) +} + func TestForEachRow(t *testing.T) { t.Parallel()