Skip to content

[+] teach Rows.CloseError to set the error#241

Merged
pashagolub merged 1 commit intopashagolub:masterfrom
theory:fix-close-error-issue
Aug 19, 2025
Merged

[+] teach Rows.CloseError to set the error#241
pashagolub merged 1 commit intopashagolub:masterfrom
theory:fix-close-error-issue

Conversation

@theory
Copy link
Contributor

@theory theory commented Aug 9, 2025

Rows.Close doesn't return an error, so up to now Rows.CloseError was a no-op. However, pgx's Rows.Err can return an error after Rows.Next returns false, or after Rows.Close has been called.

Add rowSets.close() to mark the current rows closed, jump the record number to the last row, and to set the close error for that row. Then have rowSets.Close() call it and rowSets.Next() call it once it has processed the last row. These changes cause both Rows.Err and Rows.Scan to return the close error once it has been set. Add tests for this behavior.

While at it, have Rows.Scan return immediately when the rows have been closed, rather than carrying out all the scanning.

Add tests to test these behaviors.

Fixes #238.

Authors:

`Rows.Close` doesn't return an error, so up to now `Rows.CloseError` was
a no-op. However, pgx's `Rows.Err` can return an error after `Rows.Next`
returns false, or after `Rows.Close` has been called.

Add `rowSets.close()` to mark the current rows closed, jump the record
number to the last row, and to set the close error for that row. Then
have `rowSets.Close()` call it and `rowSets.Next()` call it once it has
processed the last row. These changes cause both `Rows.Err` and
`Rows.Scan` to return the close error once it has been set. Add tests
for this behavior.

While at it, have `Rows.Scan` return immediately when the rows have been
closed, rather than carrying out all the scanning.

Add tests to test these behaviors.

Fixes pashagolub#238.

Authors:
*   asayapini <asayapini@ozon.ru>
*   David E. Wheeler <david@justatheory.com>
@pashagolub pashagolub changed the title Teach Rows.CloseError to set the error [+] teach Rows.CloseError to set the error Aug 19, 2025
@pashagolub pashagolub self-assigned this Aug 19, 2025
@pashagolub pashagolub added the enhancement New feature or request label Aug 19, 2025
@pashagolub
Copy link
Owner

Thanks!

@pashagolub pashagolub merged commit d07ccec into pashagolub:master Aug 19, 2025
3 checks passed
@coveralls
Copy link

Coverage Status

coverage: 93.977% (-0.01%) from 93.988%
when pulling 1d86a3d on theory:fix-close-error-issue
into 3d7b1b7 on pashagolub:master.

@theory theory deleted the fix-close-error-issue branch October 27, 2025 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Method to return error from Rows after Rows.Next returns false

3 participants