tedious
semver
>=18.0.0postconditions26functions13last verified2026-04-17coverage score100%Postconditions — what we check
- connect · connection-failureerrorWhenCannot connect (wrong credentials, server unreachable, etc.)Throws
ConnectionError event with detailsRequired handlingCaller MUST handle 'error' event on Connection. Common error codes: - ESOCKET: Network/socket error - ELOGIN: Authentication failed - ETIMEOUT: Connection timeout Implement retry with exponential backoff for transient issues.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - execSql · syntax-errorerrorWhenSQL syntax errorThrows
Error event on Request with error.number indicating syntax errorRequired handlingCaller MUST handle 'error' event on Request. SQL Server error numbers: - 102, 156: Syntax errors - 207: Invalid column name - 208: Invalid object name (table not found) DO NOT retry - fix SQL syntax.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[2] - execSql · constraint-violationerrorWhenUnique constraint, foreign key, or NOT NULL violationThrows
Error event with error.number for constraint violationsRequired handlingCaller MUST handle constraint violations: - 2627: Unique constraint violation - 547: Foreign key constraint violation - 515: NOT NULL constraint violation Extract details from error.message. DO NOT retry without fixing data.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[3] - execSql · connection-errorerrorWhenConnection lost during query executionThrows
Error event with connection-related error codesRequired handlingCaller MUST handle connection errors. Connection may be lost due to timeout or server restart. Implement retry with exponential backoff.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - execSql · deadlockerrorWhenTransaction deadlock detectedThrows
Error event with error.number = 1205Required handlingCaller MUST handle deadlock errors. Deadlocks are transient - implement retry logic. SQL Server automatically rolls back deadlocked transaction. Consider transaction isolation level and lock hints to reduce deadlocks.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[4] - execSql · timeouterrorWhenQuery execution timeout exceededThrows
Error event with ETIMEOUT codeRequired handlingCaller MUST handle timeout errors. Query took longer than request timeout setting. Consider optimizing query or increasing timeout.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[2] - callProcedure · procedure-errorerrorWhenStored procedure raises error or does not existThrows
Error event on Request with SQL Server error numberRequired handlingCaller MUST handle 'error' event on Request. Error numbers: - 2812: Procedure not found - Application errors: RAISERROR in procedure Check error.number and error.message for details.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[2] - callProcedure · connection-errorerrorWhenConnection lost during procedure callThrows
Error event with connection-related error codesRequired handlingCaller MUST handle connection errors. Implement retry with exponential backoff for transient issues.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - beginTransaction · transaction-start-errorerrorWhenCannot start transaction due to connection issuesThrows
Error event on Connection with transaction error detailsRequired handlingCaller MUST handle 'error' event on Connection. Connection must be in LoggedIn state to begin transaction. Ensure no other transaction is active on connection.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - beginTransaction · nested-transaction-errorerrorWhenAttempting to begin transaction when one is already activeThrows
Error event indicating transaction already in progressRequired handlingCaller MUST track transaction state. SQL Server supports nested transactions via SAVE TRANSACTION. Consider using savepoints for nested logic.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[5] - commitTransaction · commit-errorerrorWhenCannot commit transaction (constraint violation, business rule failure)Throws
Error event on Connection with commit failure detailsRequired handlingCaller MUST handle 'error' event on Connection. Commit can fail if deferred constraints are violated. Transaction will be rolled back automatically on commit failure.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - commitTransaction · no-active-transactionerrorWhenAttempting to commit when no transaction is activeThrows
Error event indicating no transaction to commitRequired handlingCaller MUST track transaction state. Ensure beginTransaction was called and no prior rollback occurred.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - rollbackTransaction · rollback-errorerrorWhenCannot rollback transaction (connection lost)Throws
Error event on Connection with rollback failure detailsRequired handlingCaller MUST handle 'error' event on Connection. Rollback rarely fails; if it does, connection may be unusable. Consider closing and reopening connection after rollback failure.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - rollbackTransaction · no-active-transactionerrorWhenAttempting to rollback when no transaction is activeThrows
Error event indicating no transaction to rollbackRequired handlingCaller MUST track transaction state. Ensure beginTransaction was called.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - prepare · prepare-errorerrorWhenSQL syntax error or invalid statementThrows
Error event on Request with SQL Server error detailsRequired handlingCaller MUST handle 'error' event on Request. Prepare validates SQL syntax before execution. Error numbers same as execSql (102, 156, 207, 208).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[2] - unprepare · unprepare-errorerrorWhenCannot unprepare statement (connection lost, invalid handle)Throws
Error event on Request with error detailsRequired handlingCaller MUST handle 'error' event on Request. Unprepare should always be called to free server resources.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[2] - execute · execute-parameter-validation-errorerrorWhenParameter value type does not match the declared parameter type (e.g., passing a string where an Int parameter is expected). Validation runs synchronously in execute() via DataType.validate() before any network call.Throws
RequestError delivered to Request callback (code: undefined)Required handlingCaller MUST handle 'error' event on the Request object. Parameter type mismatches are caught before the request is sent to SQL Server. Validate parameter types before calling execute(). The same error handler used for prepare()/unprepare() MUST also cover execute().costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - execute · execute-invalid-state-errorerrorWhenexecute() is called while the connection is not in LOGGED_IN state — e.g., a prior request is still in-flight, or the connection is closing. SQL Server allows only one request at a time per connection.Throws
RequestError with code 'EINVALIDSTATE' delivered to Request callbackRequired handlingCaller MUST wait for the previous request's callback before calling execute(). Only one request at a time per Connection is allowed. Use connection pooling (e.g., mssql) to run concurrent queries. Always handle the 'error' event.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible - execBulkLoad · bulk-load-constraint-violationerrorWhenBulk insert violates a table constraint — e.g., unique key violation (error 2627), foreign key constraint (error 547), NOT NULL constraint (error 515) — when checkConstraints is enabled in BulkLoad options. Without checkConstraints, SQL Server may bypass constraint checks, causing silent data corruption.Throws
Error delivered to BulkLoad callback (err.number = 2627 | 547 | 515)Required handlingCaller MUST handle error in the BulkLoad callback: newBulkLoad(table, options, (err, rowCount) => { if (err) { /* handle constraint violation */ } }). Consider enabling checkConstraints: true option to catch violations during insert. Log rowCount on success to confirm all rows were inserted.costhighin prodimmediate exceptionusers seedegraded performancevisibilitysilent - execBulkLoad · bulk-load-column-definition-mismatcherrorWhenColumn definitions added via bulkLoad.addColumn() do not match the actual table schema (wrong data type, wrong nullable flag, or column doesn't exist). This causes the bulk insert to fail. Attempting to call addColumn() after rows have already been written throws synchronously: "Columns cannot be added to bulk insert after the first row has been written."Throws
Error thrown synchronously from addColumn() OR Error delivered to BulkLoad callbackRequired handlingCall addColumn() for ALL columns before writing any rows. Verify column definitions against the live table schema before performing bulk load operations. Always handle the BulkLoad callback for schema errors that surface at insert time.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[7] - execBulkLoad · bulk-load-timeouterrorWhenBulk load exceeds the timeout configured via bulkLoad.setTimeout() or the connection's requestTimeout. Large datasets or slow networks can exceed the timeout, resulting in the bulk load being considered failed.Throws
RequestError with code 'ETIMEOUT' delivered to BulkLoad callbackRequired handlingSet an appropriate timeout with bulkLoad.setTimeout(ms) for large bulk operations. Default is the Connection's requestTimeout (default: 15000ms). For large datasets, use setTimeout(0) for no timeout or increase it explicitly. Handle ETIMEOUT in the callback and implement retry logic for transient failures.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible - saveTransaction · save-transaction-state-errorerrorWhensaveTransaction() is called when no active transaction exists, or the connection is not in LOGGED_IN state (e.g., a prior request is still pending, connection is closing). SQL Server requires an active transaction for savepoints.Throws
RequestError with code 'EINVALIDSTATE' delivered to saveTransaction callbackRequired handlingCaller MUST check that beginTransaction() has been called before saveTransaction(). Wait for each request's callback to complete before issuing the next request. Always handle the err argument in the saveTransaction callback.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - saveTransaction · save-transaction-connection-errorerrorWhenConnection is lost while setting the savepoint. Network failure or server restart during the TRANSACTION_MANAGER request causes an error in the callback.Throws
ConnectionError delivered to saveTransaction callbackRequired handlingCaller MUST handle error in the saveTransaction callback. On connection error, the parent transaction state is undefined — roll back and reconnect.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - transaction · transaction-begin-errorerrorWhenTransaction cannot be started — connection is not in LOGGED_IN state (EINVALIDSTATE), or the connection was lost before beginTransaction completed. The error is delivered to the cb callback: cb(err) with no done argument.Throws
RequestError or ConnectionError delivered to cb(err)Required handlingCaller MUST check the err argument in the transaction callback before using done(). If err is set, do NOT call done() — the transaction was never started. Example: connection.transaction((err, done) => { if (err) return handleError(err); ... })costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - transaction · transaction-commit-errorerrorWhenTransaction commit fails due to deferred constraint violation, connection loss, or server error during COMMIT. The error is delivered through the done() callback: done(err). If the commit fails and the connection is still LOGGED_IN, tedious automatically attempts to rollback before passing the error to done().Throws
RequestError or ConnectionError delivered through done(err)Required handlingCaller MUST handle the err argument in the done() callback. On commit error, do NOT retry the transaction without re-starting it from beginTransaction. The automatic rollback in tedious's transaction() helper means the transaction is already rolled back when done(err) is called. Example: done(err) => { if (err) { /* transaction was rolled back */ } }costhighin prodimmediate exceptionusers seedegraded performancevisibilitysilentSources[1] - execSqlBatch · exec-sql-batch-invalid-stateerrorWhenexecSqlBatch() is called while the connection is not in LOGGED_IN state — another request is in-flight, the connection is closing, or was never established. Error message: "Requests can only be made in the LoggedIn state, not the X state."Throws
RequestError with code 'EINVALIDSTATE' delivered to Request callbackRequired handlingCaller MUST wait for the previous request's callback before calling execSqlBatch(). Only one request per connection is allowed at a time. Handle the 'error' event on the Request object.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible
Sources
Every postcondition cites at least one of these. Numbered to match the footnotes above.
- [1]tediousjs.github.io/tedious/api-connection.htmlhttps://tediousjs.github.io/tedious/api-connection.html
- [2]tediousjs.github.io/tedious/api-request.htmlhttps://tediousjs.github.io/tedious/api-request.html
- [3]docs.microsoft.com/en-us/sqlhttps://docs.microsoft.com/en-us/sql/relational-databases/errors-events/database-engine-events-and-errors
- [4]docs.microsoft.com/en-us/sqlhttps://docs.microsoft.com/en-us/sql/relational-databases/sql-server-transaction-locking-and-row-versioning-guide
- [5]docs.microsoft.com/en-us/sqlhttps://docs.microsoft.com/en-us/sql/t-sql/language-elements/begin-transaction-transact-sql
- [6]tediousjs.github.io/tedious/frequently-encountered-problems.htmlhttps://tediousjs.github.io/tedious/frequently-encountered-problems.html
- [7]tediousjs.github.io/tedious/bulk-load.htmlhttps://tediousjs.github.io/tedious/bulk-load.html
Need a different package?
Request a profile