Skip to content

Error Reference

TensorDB uses structured error codes for all SQL-related errors, enabling programmatic error handling and providing helpful suggestions.

Error Code Format

All error codes follow the pattern T<NNNN> where the first digit indicates the category:

RangeCategoryDescription
T1xxxSyntaxSQL parsing and syntax errors
T2xxxSchemaTable, column, index, and view resolution errors
T3xxxConstraintNOT NULL, UNIQUE, and primary key violations
T4xxxExecutionRuntime errors (timeout, memory, division by zero)
T6xxxAuthPermission and authentication errors

Error Codes

Syntax Errors (T1xxx)

CodeNameDescription
T1001SyntaxErrorGeneral SQL syntax error
T1002UnexpectedTokenUnexpected token in SQL statement
T1003UnterminatedStringString literal not properly closed
T1004UnknownKeywordUnrecognized SQL keyword
T1005TrailingTokensUnexpected tokens after valid statement

Schema Errors (T2xxx)

CodeNameDescription
T2001TableNotFoundReferenced table does not exist
T2002ColumnNotFoundReferenced column does not exist on table
T2003TableAlreadyExistsTable already exists (on CREATE TABLE)
T2004IndexNotFoundReferenced index does not exist
T2005IndexAlreadyExistsIndex already exists (on CREATE INDEX)
T2006ViewNotFoundReferenced view does not exist
T2007TypeMismatchType mismatch in expression or assignment

Constraint Errors (T3xxx)

CodeNameDescription
T3001NotNullViolationNULL value in NOT NULL column
T3002UniqueViolationDuplicate value in UNIQUE column
T3003PkViolationPrimary key constraint violation

Execution Errors (T4xxx)

CodeNameDescription
T4001DivisionByZeroDivision by zero in expression
T4002InvalidCastInvalid type cast
T4003QueryTimeoutQuery exceeded QUERY_TIMEOUT limit
T4004MemoryLimitExceededQuery exceeded QUERY_MAX_MEMORY limit
T4005ExecutionErrorGeneral execution error

Auth Errors (T6xxx)

CodeNameDescription
T6001PermissionDeniedInsufficient privileges for operation
T6002AuthRequiredAuthentication required

Error Structure

Each SQL error carries:

pub struct SqlError {
pub code: ErrorCode, // Stable numeric error code
pub message: String, // Human-readable error message
pub suggestion: Option<String>, // "Did you mean 'users'?"
pub position: Option<usize>, // Token position in query
}

“Did You Mean?” Suggestions

When a table or column name is misspelled, TensorDB uses Levenshtein distance to suggest the closest match:

SELECT * FROM usrs;
-- Error T2001: table or view usrs does not exist
-- Hint: Did you mean 'users'?

Handling Errors

Rust

use tensordb::{Database, Config, TensorError, SqlError, ErrorCode};
match db.sql("SELECT * FROM nonexistent") {
Ok(results) => println!("{:?}", results),
Err(TensorError::SqlExec(err)) => {
eprintln!("Error {}: {}", err.code.code_str(), err.message);
if let Some(hint) = &err.suggestion {
eprintln!(" Hint: {}", hint);
}
// Programmatic handling by error code
match err.code {
ErrorCode::TableNotFound => { /* handle missing table */ }
ErrorCode::QueryTimeout => { /* handle timeout */ }
_ => { /* other errors */ }
}
}
Err(e) => eprintln!("Other error: {}", e),
}

Error Display Format

Errors display with their code prefix:

T2001: table or view users does not exist
Hint: Did you mean 'users'?
T1001: unexpected trailing tokens
T4003: query timed out after 5023ms (limit: 5000ms)

Common Errors

ErrorCauseSolution
T1001: unexpected trailing tokensExtra tokens after SQL statementCheck SQL syntax
T2001: table X does not existMissing tableCREATE TABLE first
T2002: column X does not existWrong column nameCheck DESCRIBE table
T3001: NOT NULL violationNULL in NOT NULL columnProvide a value
T4003: query timed outSlow queryOptimize query or increase QUERY_TIMEOUT
T4004: memory limit exceededLarge result setAdd filters or increase QUERY_MAX_MEMORY

Result Type

pub type Result<T> = std::result::Result<T, TensorError>;

All TensorDB functions return tensordb::Result<T>, which is an alias for std::result::Result<T, TensorError>.