Skip to content

Preserve primary exceptions in unbuffered grid reads - #2274

Merged
mgravell merged 1 commit into
DapperLib:mainfrom
tuncaypeker:fix/grid-reader-preserve-read-exception
Nov 24, 2026
Merged

mgravell merged 1 commit into
DapperLib:mainfrom
tuncaypeker:fix/grid-reader-preserve-read-exception

Conversation

@tuncaypeker

Copy link
Copy Markdown
Contributor

Fixes #2092.

When an unbuffered grid read or row conversion throws, OnAfterGridAsync still runs in the iterator's finally block. If advancing the reader also throws, that second exception replaces the original read error, including cancellation.

Keep rethrowing the original exception and suppress an error from OnAfterGridAsync only while that exception is propagating. Normal completion and early disposal still advance the grid and surface any failure from that operation. The change is limited to GridReader.ReadUnbufferedAsync; buffered and synchronous reads are unchanged.

Validation:

  • Nine regression cases cover read errors, cancellation errors, conversion errors, next-result failures, normal completion, and early disposal.
  • Before the production change: three cases fail because the next-result exception hides the original error; six controls pass.
  • After the change: all nine cases pass.
  • Selected regression, wrapped-reader, type-mapping, multi-map, and SQLite tests pass on net481 (36), net8.0 (42), and net10.0 (42).
  • Existing AsyncTests and QueryMultipleTests pass against SQL Server 2025 LocalDB on net10.0: 154 passed, four benchmark cases skipped by the suite. Both Microsoft.Data.SqlClient and System.Data.SqlClient are covered.
  • The full repository test suite was not run.
  • Release build of Dapper/Dapper.csproj succeeds for net461, netstandard2.0, net8.0, and net10.0 with zero warnings and errors.

@mgravell mgravell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. The original read/cancellation error is preserved, and the suppression only applies while that error is propagating, so normal completion and early exit still surface failures from advancing the grid. Thanks!

@mgravell
mgravell merged commit 6d7d3f6 into DapperLib:main Nov 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SqlMapper.GridReader.ReadUnbufferedAsync possibly hiding exceptions

2 participants