pub struct QueryError {
pub code: ErrorCode,
pub message: String,
pub context: ErrorContext,
pub source: Option<Box<dyn Error + Send + Sync>>,
}Expand description
Errors that can occur during query operations.
Fields§
§code: ErrorCodeThe error code.
message: StringThe error message.
context: ErrorContextAdditional context.
source: Option<Box<dyn Error + Send + Sync>>The source error (if any).
Implementations§
Source§impl QueryError
impl QueryError
Sourcepub fn new(code: ErrorCode, message: impl Into<String>) -> Self
pub fn new(code: ErrorCode, message: impl Into<String>) -> Self
Create a new error with the given code and message.
Sourcepub fn with_context(self, operation: impl Into<String>) -> Self
pub fn with_context(self, operation: impl Into<String>) -> Self
Add context about the operation.
Sourcepub fn with_suggestion(self, suggestion: impl Into<String>) -> Self
pub fn with_suggestion(self, suggestion: impl Into<String>) -> Self
Add a suggestion for fixing the error.
Sourcepub fn with_code_suggestion(
self,
text: impl Into<String>,
code: impl Into<String>,
) -> Self
pub fn with_code_suggestion( self, text: impl Into<String>, code: impl Into<String>, ) -> Self
Add a code suggestion.
Sourcepub fn with_model(self, model: impl Into<String>) -> Self
pub fn with_model(self, model: impl Into<String>) -> Self
Set the model.
Sourcepub fn with_field(self, field: impl Into<String>) -> Self
pub fn with_field(self, field: impl Into<String>) -> Self
Set the field.
Sourcepub fn with_source<E: Error + Send + Sync + 'static>(self, source: E) -> Self
pub fn with_source<E: Error + Send + Sync + 'static>(self, source: E) -> Self
Set the source error.
Sourcepub fn not_unique(model: impl Into<String>) -> Self
pub fn not_unique(model: impl Into<String>) -> Self
Create a not unique error.
Sourcepub fn constraint_violation(
model: impl Into<String>,
message: impl Into<String>,
) -> Self
pub fn constraint_violation( model: impl Into<String>, message: impl Into<String>, ) -> Self
Create a constraint violation error.
Sourcepub fn unique_violation(
model: impl Into<String>,
field: impl Into<String>,
) -> Self
pub fn unique_violation( model: impl Into<String>, field: impl Into<String>, ) -> Self
Create a unique constraint violation error.
Sourcepub fn foreign_key_violation(
model: impl Into<String>,
relation: impl Into<String>,
) -> Self
pub fn foreign_key_violation( model: impl Into<String>, relation: impl Into<String>, ) -> Self
Create a foreign key violation error.
Sourcepub fn not_null_violation(
model: impl Into<String>,
field: impl Into<String>,
) -> Self
pub fn not_null_violation( model: impl Into<String>, field: impl Into<String>, ) -> Self
Create a not null violation error.
Sourcepub fn invalid_input(
field: impl Into<String>,
message: impl Into<String>,
) -> Self
pub fn invalid_input( field: impl Into<String>, message: impl Into<String>, ) -> Self
Create an invalid input error.
Sourcepub fn connection(message: impl Into<String>) -> Self
pub fn connection(message: impl Into<String>) -> Self
Create a connection error.
Sourcepub fn connection_timeout(duration_ms: u64) -> Self
pub fn connection_timeout(duration_ms: u64) -> Self
Create a connection timeout error.
Sourcepub fn pool_exhausted(max_connections: u32) -> Self
pub fn pool_exhausted(max_connections: u32) -> Self
Create a pool exhausted error.
Sourcepub fn authentication_failed(message: impl Into<String>) -> Self
pub fn authentication_failed(message: impl Into<String>) -> Self
Create an authentication error.
Sourcepub fn transaction(message: impl Into<String>) -> Self
pub fn transaction(message: impl Into<String>) -> Self
Create a transaction error.
Sourcepub fn sql_syntax(message: impl Into<String>, sql: impl Into<String>) -> Self
pub fn sql_syntax(message: impl Into<String>, sql: impl Into<String>) -> Self
Create an SQL syntax error.
Sourcepub fn serialization(message: impl Into<String>) -> Self
pub fn serialization(message: impl Into<String>) -> Self
Create a serialization error.
Sourcepub fn deserialization(message: impl Into<String>) -> Self
pub fn deserialization(message: impl Into<String>) -> Self
Create a deserialization error.
Sourcepub fn unsupported(message: impl Into<String>) -> Self
pub fn unsupported(message: impl Into<String>) -> Self
Create an unsupported operation error.
Sourcepub fn is_not_found(&self) -> bool
pub fn is_not_found(&self) -> bool
Check if this is a not found error.
Sourcepub fn is_constraint_violation(&self) -> bool
pub fn is_constraint_violation(&self) -> bool
Check if this is a constraint violation.
Sourcepub fn is_timeout(&self) -> bool
pub fn is_timeout(&self) -> bool
Check if this is a timeout error.
Sourcepub fn is_connection_error(&self) -> bool
pub fn is_connection_error(&self) -> bool
Check if this is a connection error.
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Check if this error is retryable.
Sourcepub fn error_code(&self) -> &ErrorCode
pub fn error_code(&self) -> &ErrorCode
Get the error code.
Sourcepub fn display_full(&self) -> String
pub fn display_full(&self) -> String
Display the full error with all context and suggestions.
Sourcepub fn display_colored(&self) -> String
pub fn display_colored(&self) -> String
Display error with ANSI colors for terminal output.
Trait Implementations§
Source§impl Debug for QueryError
impl Debug for QueryError
Source§impl Display for QueryError
impl Display for QueryError
Source§impl Error for QueryError
impl Error for QueryError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()