Skip to content

fix: give execute() the last error when the server sends several - #1989

Merged
dhensby merged 1 commit into
tediousjs:masterfrom
dhensby:claude/clever-galileo-627a80
Nov 27, 2026
Merged

dhensby merged 1 commit into
tediousjs:masterfrom
dhensby:claude/clever-galileo-627a80

Conversation

@dhensby

@dhensby dhensby commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

What this does:

When the server sends two or more errors for a request, tedious 15+ calls the request back with one AggregateError that holds them all. query() already matched each error in it with the errors that the connection had emitted. execute() compared only the message of the AggregateError, which is empty, so it added the AggregateError as one more error.

So on tedious, request.execute() and preparedStatement.execute() rejected with an error that had an empty message, and the real last error was in precedingErrors. In stream mode the request emitted an extra error event with an empty message. For example, a procedure that runs raiserror('first', 16, 1); raiserror('second', 16, 1):

Before After
execute() rejects with '' 'second'
precedingErrors ['first', 'second'] ['first']
stream error events 'first', 'second', '' 'first', 'second'

query() and execute() now use one method to add the error from tedious's callback. It finds the position of the reported errors once, before it adds any, so an error that does not match does not move the others.

Unit tests cover query() and execute() with a fake tedious connection. A new integration test covers execute(), a stream and a prepared statement on tedious. I ran npm run test-tedious on tedious 19.2.2 and 20.4.3.

Related issues:

Found in the review of #1980. It does not need a value handler, and it was already on master.

Pre/Post merge checklist:

  • Update change log

🤖 Generated with Claude Code

When the server sends two or more errors for a request, tedious 15+
calls the request back with one AggregateError that holds them all.
query() matched each error in it with the errors that the connection
had emitted. execute() compared only the message of the AggregateError,
which is empty, so it added the AggregateError as one more error.

So execute(), and execute() of a prepared statement, rejected with an
error that had an empty message, and the last error from the server was
in precedingErrors. A stream emitted the AggregateError as an extra
error with an empty message.

query() and execute() now use one method, which compares each error in
the AggregateError with the error in the same position. It finds that
position before it adds an error, so an error that does not match does
not move the others.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dhensby
dhensby marked this pull request as ready for review November 27, 2026 14:25
@dhensby
dhensby merged commit 6cfb85b into tediousjs:master Nov 27, 2026
47 checks passed
@dhensby
dhensby deleted the claude/clever-galileo-627a80 branch November 27, 2026 15:57
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 12.8.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant