Skip to content

Fix off-by-one in ThrowColumnMismatch exception message#6584

Open
BrunoSync wants to merge 1 commit into
npgsql:mainfrom
BrunoSync:fix/throw-column-mismatch-message
Open

Fix off-by-one in ThrowColumnMismatch exception message#6584
BrunoSync wants to merge 1 commit into
npgsql:mainfrom
BrunoSync:fix/throw-column-mismatch-message

Conversation

@BrunoSync
Copy link
Copy Markdown

Fixes #6583

Problem

ThrowColumnMismatch was using _column + 1 in the exception message,
but _column already holds the correct number of values written when the
method is called from StartRow. This caused the reported value count to
always be off by one.

For example, with a 3-column table where only 2 values were written:

"started with 3 column(s), but 3 value(s) were provided"

when it should say:

"started with 3 column(s), but 2 value(s) were provided"

Fix

Removed the + 1 from the interpolated string in ThrowColumnMismatch.

Test

Added Write_column_out_of_bounds_exception_message to CopyTests.cs
to verify the exception message reports the correct value count.

@BrunoSync BrunoSync requested review from roji and vonzshik as code owners May 21, 2026 23:42
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.

NpgsqlBinaryImporter Invalid exception message in ThrowColumnMismatch

1 participant