Repository navigation
fix: give bulk() the last error when the server sends several - #1992
Merged
Merged
Conversation
1 task
When the server sends two or more errors for a bulk load, tedious 15+ calls it back with one AggregateError that holds them all. bulk() compared only the message of the AggregateError, which is empty, with the last error the connection had emitted, so it added the AggregateError as one more error. So bulk() rejected with an error that had an empty message and no number, and the error from the server was in precedingErrors. This is what happens for a table that does not exist, such as a temporary table made on another connection of the pool, where the server sends "Invalid object name" twice. A stream emitted the AggregateError as an extra error with an empty message. bulk() now uses the method that query() and execute() use since f0bae04, which compares each error in the AggregateError with the error in the same position. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
bulk() reports an error from its create table statement through the same callback as the load itself. Each case for errors from the server now also runs with table.create set, so that the errors come from that statement. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dhensby
force-pushed
the
fix/bulk-multiple-errors
branch
from
December 2, 2026 11:34
47617fe to
d2e601d
Compare
dhensby
approved these changes
Dec 2, 2026
dhensby
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for this. It makes bulk() match what #1989 did for query() and execute(), and I've checked the fix against a server on tedious 19 and 20.
I've pushed one test commit. The multiple-error cases now also run with table.create set, because the create table statement reports through the same done and can also fail with more than one error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does:
On tedious,
bulk()rejects with an empty error when SQL Server sends more than one error for the load. The most common case is a table that doesn't exist, and that includes a#temptable created on a different connection of the pool:In that case the server sends "Invalid object name" twice, and tedious 15+ calls the bulk load back with one
AggregateErrorthat holds both errors._bulk()still has the check that #1989 replaced inquery()andexecute(). It compares theAggregateError's message, which is empty, with the last error it collected, so it adds theAggregateErroras one more error and rejects with that. The real errors end up inprecedingErrors, and a stream emits an extraerrorevent with an empty message.The fix is one line:
_bulk()'sdonenow calls_addCallbackError(), asquery()andexecute()do. That also covers thecreate tablestatement, because it reports through the samedone. A single error from the server, and errors that tedious makes itself (timeouts, validation), are handled the same as before.Tests:
bulkto theerrors from the server (tedious)loop, withnewBulkLoadandexecBulkLoadon the stub connection. On master, 3 of the 5 cases fail: two errors, two errors with the same message, and the stream. All 5 pass with this change.bulk load into a table that does not exist. Like the other multiple-error tests it's registered for tedious only, because msnodesqlv8 reports a missing table with its own message and never builds anAggregateError.What I ran:
npm test(standard and 579 unit tests) and commitlint both pass.npm run test-tediousagainst SQL Server 2022 in Docker, with tedious 19.2.2 and with 20.4.3: 230 passing and 5 pending on both. On master the new test is the only failure, with'' !== "Invalid object name 'bulk_table_missing'."on both tedious versions.npm run test-clipasses.Prepared with the help of an AI coding agent.
Related issues:
None found.
Pre/Post merge checklist: