pub struct Error { /* private fields */ }Expand description
Represents an error in SurrealDB
Designed to be returned from public APIs (including over the wire). It is
wire-friendly and non-lossy: serialization preserves kind, message,
and optional details. Use this type whenever an error crosses
an API boundary (e.g. server response, SDK method return).
The details field is flattened into the serialized object, so the wire
format contains kind (string) and optionally details (object) at the
same level as code and message. The optional cause field allows
error chaining so that SDKs can receive and display full error chains.
Implementations§
Source§impl Error
impl Error
Sourcepub fn validation(
message: String,
details: impl Into<Option<ValidationError>>,
) -> Self
pub fn validation( message: String, details: impl Into<Option<ValidationError>>, ) -> Self
Validation error (parse error, invalid request or params), with optional structured details.
When details is provided, the wire code is set from the variant (e.g. Parse →
PARSE_ERROR).
Sourcepub fn not_allowed(
message: String,
details: impl Into<Option<NotAllowedError>>,
) -> Self
pub fn not_allowed( message: String, details: impl Into<Option<NotAllowedError>>, ) -> Self
Not-allowed error (e.g. method, scripting, function, net target), with optional
structured details. When details is provided, the wire code is set from the variant.
Sourcepub fn configuration(
message: String,
details: impl Into<Option<ConfigurationError>>,
) -> Self
pub fn configuration( message: String, details: impl Into<Option<ConfigurationError>>, ) -> Self
Configuration error (feature or config not supported), with optional structured details.
When details is provided, the wire code is set from the variant.
Sourcepub fn thrown(message: String) -> Self
pub fn thrown(message: String) -> Self
User-thrown error (e.g. from THROW in SurrealQL). Sets wire code for RPC.
Sourcepub fn query(message: String, details: impl Into<Option<QueryError>>) -> Self
pub fn query(message: String, details: impl Into<Option<QueryError>>) -> Self
Query execution error (not executed, timeout, cancelled), with optional structured details.
When details is provided, the wire code is set from the variant.
Sourcepub fn serialization(
message: String,
details: impl Into<Option<SerializationError>>,
) -> Self
pub fn serialization( message: String, details: impl Into<Option<SerializationError>>, ) -> Self
Serialisation or deserialisation error, with optional structured details.
When details is provided, the wire code is set from the variant.
Sourcepub fn not_found(
message: String,
details: impl Into<Option<NotFoundError>>,
) -> Self
pub fn not_found( message: String, details: impl Into<Option<NotFoundError>>, ) -> Self
Resource not found (e.g. table, record, namespace, RPC method), with optional
structured details. When details is NotFoundError::Method, the wire code is set to
METHOD_NOT_FOUND for RPC backwards compatibility.
Sourcepub fn already_exists(
message: String,
details: impl Into<Option<AlreadyExistsError>>,
) -> Self
pub fn already_exists( message: String, details: impl Into<Option<AlreadyExistsError>>, ) -> Self
Resource already exists (e.g. table, record), with optional structured details.
Sourcepub fn connection(
message: String,
details: impl Into<Option<ConnectionError>>,
) -> Self
pub fn connection( message: String, details: impl Into<Option<ConnectionError>>, ) -> Self
Connection error (e.g. uninitialised, already connected), with optional structured details. Used in the SDK for client-side connection state errors.
Sourcepub fn internal(message: String) -> Self
pub fn internal(message: String) -> Self
Internal or unexpected error (server or client). Sets wire code for RPC.
Sourcepub fn cause(&self) -> Option<&Error>
pub fn cause(&self) -> Option<&Error>
Returns the optional underlying cause for error chaining.
Sourcepub fn with_cause(self, cause: Error) -> Self
pub fn with_cause(self, cause: Error) -> Self
Returns an error with the given cause attached. Consumes self.
Sourcepub fn kind_str(&self) -> &'static str
pub fn kind_str(&self) -> &'static str
Returns the kind string for this error (e.g. “NotAllowed”, “Internal”).
Sourcepub fn details(&self) -> &ErrorDetails
pub fn details(&self) -> &ErrorDetails
Returns the error details (always present). The variant determines the error kind.
Sourcepub fn is_validation(&self) -> bool
pub fn is_validation(&self) -> bool
Returns true if this is a validation error.
Sourcepub fn is_configuration(&self) -> bool
pub fn is_configuration(&self) -> bool
Returns true if this is a configuration error.
Sourcepub fn is_serialization(&self) -> bool
pub fn is_serialization(&self) -> bool
Returns true if this is a serialization error.
Sourcepub fn is_not_allowed(&self) -> bool
pub fn is_not_allowed(&self) -> bool
Returns true if this is a not-allowed error.
Sourcepub fn is_not_found(&self) -> bool
pub fn is_not_found(&self) -> bool
Returns true if this is a not-found error.
Sourcepub fn is_already_exists(&self) -> bool
pub fn is_already_exists(&self) -> bool
Returns true if this is an already-exists error.
Sourcepub fn is_connection(&self) -> bool
pub fn is_connection(&self) -> bool
Returns true if this is a connection error.
Sourcepub fn is_internal(&self) -> bool
pub fn is_internal(&self) -> bool
Returns true if this is an internal error.
Sourcepub fn validation_details(&self) -> Option<&ValidationError>
pub fn validation_details(&self) -> Option<&ValidationError>
Returns structured validation error details, if this is a validation error with specifics.
Sourcepub fn not_allowed_details(&self) -> Option<&NotAllowedError>
pub fn not_allowed_details(&self) -> Option<&NotAllowedError>
Returns structured not-allowed error details, if this is a not-allowed error with specifics.
Sourcepub fn configuration_details(&self) -> Option<&ConfigurationError>
pub fn configuration_details(&self) -> Option<&ConfigurationError>
Returns structured configuration error details, if this is a configuration error with specifics.
Sourcepub fn serialization_details(&self) -> Option<&SerializationError>
pub fn serialization_details(&self) -> Option<&SerializationError>
Returns structured serialization error details, if this is a serialization error with specifics.
Sourcepub fn not_found_details(&self) -> Option<&NotFoundError>
pub fn not_found_details(&self) -> Option<&NotFoundError>
Returns structured not-found error details, if this is a not-found error with specifics.
Sourcepub fn query_details(&self) -> Option<&QueryError>
pub fn query_details(&self) -> Option<&QueryError>
Returns structured query error details, if this is a query error with specifics.
Sourcepub fn already_exists_details(&self) -> Option<&AlreadyExistsError>
pub fn already_exists_details(&self) -> Option<&AlreadyExistsError>
Returns structured already-exists error details, if this is an already-exists error with specifics.
Sourcepub fn connection_details(&self) -> Option<&ConnectionError>
pub fn connection_details(&self) -> Option<&ConnectionError>
Returns structured connection error details, if this is a connection error with specifics.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
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()
Source§impl From<ConversionError> for Error
impl From<ConversionError> for Error
Source§fn from(e: ConversionError) -> Self
fn from(e: ConversionError) -> Self
Source§impl From<LengthMismatchError> for Error
impl From<LengthMismatchError> for Error
Source§fn from(e: LengthMismatchError) -> Self
fn from(e: LengthMismatchError) -> Self
Source§impl From<OutOfRangeError> for Error
impl From<OutOfRangeError> for Error
Source§fn from(e: OutOfRangeError) -> Self
fn from(e: OutOfRangeError) -> Self
Source§impl SurrealValue for Error
impl SurrealValue for Error
Source§fn into_value(self) -> Value
fn into_value(self) -> Value
impl Eq for Error
impl StructuralPartialEq for Error
Auto Trait Implementations§
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
impl UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more