Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Npgsql/NpgsqlBinaryImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ enum ImporterState
#endregion Enums

void ThrowColumnMismatch()
=> throw new InvalidOperationException($"The binary import operation was started with {NumColumns} column(s), but {_column + 1} value(s) were provided.");
=> throw new InvalidOperationException($"The binary import operation was started with {NumColumns} column(s), but {_column} value(s) were provided.");

#region Tracing

Expand Down
16 changes: 16 additions & 0 deletions test/Npgsql.Tests/CopyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,22 @@ public async Task Write_column_out_of_bounds_throws()
Assert.Throws<InvalidOperationException>(() => writer.WriteRow("Hello", 8, "I should not be here"));
}

[Test, IssueLink("https://github.com/npgsql/npgsql/issues/6583")]
public async Task Write_column_out_of_bounds_exception_message()
{
using var conn = await OpenConnectionAsync();
var table = await CreateTempTable(conn, "foo INT, bar TEXT");

using var writer = conn.BeginBinaryImport($"COPY {table} (foo, bar) FROM STDIN BINARY");

writer.StartRow();
writer.Write(1);

var ex = Assert.Throws<InvalidOperationException>(() => writer.StartRow());
Assert.That(ex!.Message, Does.Contain("2 column(s)"));
Assert.That(ex!.Message, Does.Contain("1 value(s)"));
}

[Test]
public async Task Cancel_raw_binary_export_when_not_consumed_and_then_Dispose()
{
Expand Down