cquill/error/format
Types
Connection configuration for connection error context
pub type ConnectionConfig {
ConnectionConfig(
host: String,
port: Int,
database: String,
user: String,
)
}
Constructors
-
ConnectionConfig( host: String, port: Int, database: String, user: String, )
Context about where an error occurred, for enriched error messages
pub type ErrorContext {
ErrorContext(
query: option.Option(String),
params: option.Option(List(ast.Value)),
source_location: option.Option(SourceLocation),
table: option.Option(String),
operation: option.Option(String),
)
}
Constructors
-
ErrorContext( query: option.Option(String), params: option.Option(List(ast.Value)), source_location: option.Option(SourceLocation), table: option.Option(String), operation: option.Option(String), )Arguments
- query
-
The SQL query that failed (if available)
- params
-
The query parameters (if available)
- source_location
-
Source location in user code (if available)
- table
-
The table being operated on (if known)
- operation
-
The operation being performed
Source location in user code where the error originated
pub type SourceLocation {
SourceLocation(file: String, line: Int, function: String)
}
Constructors
-
SourceLocation(file: String, line: Int, function: String)
Values
pub fn format_check_violation(
constraint: String,
detail: String,
context: ErrorContext,
) -> String
Format a check constraint violation
pub fn format_connection_failed(
reason: String,
config: ConnectionConfig,
) -> String
Format a connection failed error with troubleshooting hints
pub fn format_connection_failed_simple(reason: String) -> String
Format a connection failed error with minimal context
pub fn format_connection_lost(reason: String) -> String
Format a connection lost error
pub fn format_connection_timeout(
config: option.Option(ConnectionConfig),
) -> String
Format a connection timeout error
pub fn format_decode_error(
row: Int,
column: String,
expected: String,
found: String,
) -> String
Format a decode error with detailed context
pub fn format_foreign_key_violation(
constraint: String,
table: String,
column: String,
references_table: String,
references_column: String,
) -> String
Format a foreign key constraint violation with rich context
pub fn format_foreign_key_violation_error(
constraint: String,
detail: String,
context: ErrorContext,
) -> String
Format a foreign key violation from an AdapterError
pub fn format_not_found(context: ErrorContext) -> String
Format a “not found” error
pub fn format_not_null_violation(
column: String,
context: ErrorContext,
) -> String
Format a NOT NULL constraint violation
pub fn format_query_failed(
message: String,
code: option.Option(String),
context: ErrorContext,
) -> String
Format a query failed error with context
pub fn format_rich_error(
error: error.AdapterError,
context: ErrorContext,
) -> String
Format any AdapterError with rich context
pub fn format_rich_savepoint_error(
error: error.SavepointError(e),
context: ErrorContext,
) -> String
Format a savepoint error with rich context
pub fn format_rich_transaction_error(
error: error.TransactionError(e),
context: ErrorContext,
) -> String
Format a transaction error with rich context
pub fn format_too_many_rows(
expected: Int,
got: Int,
context: ErrorContext,
) -> String
Format a “too many rows” error
pub fn format_unique_violation(
constraint: String,
table: String,
column: String,
value: ast.Value,
) -> String
Format a unique constraint violation with rich context
pub fn format_unique_violation_error(
constraint: String,
detail: String,
context: ErrorContext,
) -> String
Format a unique violation from an AdapterError
pub fn format_value(value: ast.Value) -> String
Format a Value for display in error messages
pub fn with_operation(
context: ErrorContext,
operation: String,
) -> ErrorContext
Create a context with operation name
pub fn with_params(
context: ErrorContext,
params: List(ast.Value),
) -> ErrorContext
Create a context with query parameters
pub fn with_query(
context: ErrorContext,
query: String,
) -> ErrorContext
Create a context with query information
pub fn with_source_location(
context: ErrorContext,
file: String,
line: Int,
function: String,
) -> ErrorContext
Create a context with source location
pub fn with_table(
context: ErrorContext,
table: String,
) -> ErrorContext
Create a context with table name