Skip to content

Preserve primary exceptions in unbuffered grid reads - #2274

Open
tuncaypeker wants to merge 1 commit into
DapperLib:mainfrom
tuncaypeker:fix/grid-reader-preserve-read-exception
Open

tuncaypeker wants to merge 1 commit into
DapperLib:mainfrom
tuncaypeker:fix/grid-reader-preserve-read-exception

Conversation

@tuncaypeker

Copy link
Copy Markdown

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.

This branch has not been deployed

No deployments
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

1 participant