pub struct Error { /* private fields */ }Expand description
What a database operation failed with: a kind (one per PHP exception class), a message, and the integer code PHP’s exception carries.
PHP: Utopia\Database\Exception and its subclasses in
Utopia\Database\Exception\*, plus the driver and engine exceptions that
escape the library unmapped (PDOException, TypeError, …). The kind is
the class (Error::php_class); instanceof is Error::is_a (a
Kind::Unique error is also a Kind::Duplicate one, as Unique
extends Duplicate).
Implementations§
Source§impl Error
impl Error
Sourcepub fn new(kind: Kind, message: impl Into<String>) -> Self
pub fn new(kind: Kind, message: impl Into<String>) -> Self
An error of kind with message and code 0.
Sourcepub fn from_bytes(kind: Kind, message: Vec<u8>) -> Self
pub fn from_bytes(kind: Kind, message: Vec<u8>) -> Self
An error of kind whose message is bytes (PHP messages are: one can
quote a string that is not UTF-8).
Sourcepub fn with_code(self, code: i64) -> Self
pub fn with_code(self, code: i64) -> Self
The same error with a code. PHP: Utopia\Database\Exception takes an
int|string code and turns a non-numeric string into 0; pass the
integer it ends up as.
Sourcepub fn string_code(code: &[u8]) -> i64
pub fn string_code(code: &[u8]) -> i64
The integer a string code becomes (Utopia\Database\Exception’s
constructor): a numeric string is cast to an integer ("12" is 12,
" 1.9" is 1, "1e3" is 1000, beyond i64 it saturates), anything
else is 0.
use utopia_database::Error;
assert_eq!(Error::string_code(b"42"), 42);
assert_eq!(Error::string_code(b"1.5"), 1);
assert_eq!(Error::string_code(b"HY000"), 0);PHP: Utopia\Database\Exception::__construct with a string $code
(is_numeric($code) ? (int) $code : 0).
Sourcepub fn with_string_code(self, code: &[u8]) -> Self
pub fn with_string_code(self, code: &[u8]) -> Self
The same error with a string code: kept as Error::state, and as
the integer Error::string_code turns it into.
Sourcepub fn state(&self) -> Option<&str>
pub fn state(&self) -> Option<&str>
The string code the error was built with, such as a SQLSTATE
($state); None for an integer code.
Sourcepub fn with_driver_code(self, code: i64) -> Self
pub fn with_driver_code(self, code: i64) -> Self
The same error with the driver’s own error code
(PDOException::$errorInfo[1]), which [crate::connection::is_lost]
reads.
Sourcepub fn driver_code(&self) -> Option<i64>
pub fn driver_code(&self) -> Option<i64>
The driver’s own error code ($errorInfo[1]), when the error carries
one.
Sourcepub fn with_labels(self, labels: Vec<String>) -> Self
pub fn with_labels(self, labels: Vec<String>) -> Self
The same error with the server’s error labels (a MongoDB error’s
TransientTransactionError, UnknownTransactionCommitResult, …).
Sourcepub fn labels(&self) -> &[String]
pub fn labels(&self) -> &[String]
The server’s error labels (getErrorLabels()); empty when the error
carries none.
Sourcepub fn with_previous(self, previous: Error) -> Self
pub fn with_previous(self, previous: Error) -> Self
The same error wrapping previous.
Sourcepub fn order(message: impl Into<String>, attribute: Option<String>) -> Self
pub fn order(message: impl Into<String>, attribute: Option<String>) -> Self
An Kind::Order error about attribute.
Sourcepub fn is_a(&self, kind: Kind) -> bool
pub fn is_a(&self, kind: Kind) -> bool
Whether the error is of kind or of a kind extending it
(instanceof).
Sourcepub fn is_engine_error(&self) -> bool
pub fn is_engine_error(&self) -> bool
Whether the error is an engine \Error (TypeError, ValueError,
DivisionByZeroError, Error) rather than an \Exception: code
that catches Exception lets it through.
Sourcepub fn message(&self) -> &str
pub fn message(&self) -> &str
The message (getMessage()), lossy when Error::message_bytes
is not UTF-8.
Sourcepub fn message_bytes(&self) -> &[u8] ⓘ
pub fn message_bytes(&self) -> &[u8] ⓘ
The message (getMessage()) byte for byte.
Sourcepub fn attribute(&self) -> Option<&str>
pub fn attribute(&self) -> Option<&str>
The attribute of an Kind::Order error (getAttribute()).
Source§impl Error
impl Error
Sourcepub fn database(message: impl Into<String>) -> Self
pub fn database(message: impl Into<String>) -> Self
A Kind::Database error.
A Kind::Authorization error.
Sourcepub fn schema(message: impl Into<String>) -> Self
pub fn schema(message: impl Into<String>) -> Self
A Kind::Schema error.
Sourcepub fn contention(message: impl Into<String>) -> Self
pub fn contention(message: impl Into<String>) -> Self
A Kind::Contention error.
Sourcepub fn mismatch(message: impl Into<String>) -> Self
pub fn mismatch(message: impl Into<String>) -> Self
A Kind::Mismatch error.
Sourcepub fn refused(message: impl Into<String>) -> Self
pub fn refused(message: impl Into<String>) -> Self
A Kind::Refused error.
Sourcepub fn unconfirmed(message: impl Into<String>) -> Self
pub fn unconfirmed(message: impl Into<String>) -> Self
A Kind::Unconfirmed error.
Sourcepub fn exception(message: impl Into<String>) -> Self
pub fn exception(message: impl Into<String>) -> Self
A Kind::Exception error.
Sourcepub fn character(message: impl Into<String>) -> Self
pub fn character(message: impl Into<String>) -> Self
A Kind::Character error.
Sourcepub fn conflict(message: impl Into<String>) -> Self
pub fn conflict(message: impl Into<String>) -> Self
A Kind::Conflict error.
Sourcepub fn dependency(message: impl Into<String>) -> Self
pub fn dependency(message: impl Into<String>) -> Self
A Kind::Dependency error.
Sourcepub fn duplicate(message: impl Into<String>) -> Self
pub fn duplicate(message: impl Into<String>) -> Self
A Kind::Duplicate error.
Sourcepub fn index(message: impl Into<String>) -> Self
pub fn index(message: impl Into<String>) -> Self
A Kind::Index error.
Sourcepub fn limit(message: impl Into<String>) -> Self
pub fn limit(message: impl Into<String>) -> Self
A Kind::Limit error.
Sourcepub fn not_found(message: impl Into<String>) -> Self
pub fn not_found(message: impl Into<String>) -> Self
A Kind::NotFound error.
Sourcepub fn operator(message: impl Into<String>) -> Self
pub fn operator(message: impl Into<String>) -> Self
A Kind::Operator error.
Sourcepub fn query(message: impl Into<String>) -> Self
pub fn query(message: impl Into<String>) -> Self
A Kind::Query error.
Sourcepub fn relationship(message: impl Into<String>) -> Self
pub fn relationship(message: impl Into<String>) -> Self
A Kind::Relationship error.
Sourcepub fn restricted(message: impl Into<String>) -> Self
pub fn restricted(message: impl Into<String>) -> Self
A Kind::Restricted error.
Sourcepub fn structure(message: impl Into<String>) -> Self
pub fn structure(message: impl Into<String>) -> Self
A Kind::Structure error.
Sourcepub fn timeout(message: impl Into<String>) -> Self
pub fn timeout(message: impl Into<String>) -> Self
A Kind::Timeout error.
Sourcepub fn transaction(message: impl Into<String>) -> Self
pub fn transaction(message: impl Into<String>) -> Self
A Kind::Transaction error.
Sourcepub fn truncate(message: impl Into<String>) -> Self
pub fn truncate(message: impl Into<String>) -> Self
A Kind::Truncate error.
Sourcepub fn type_error(message: impl Into<String>) -> Self
pub fn type_error(message: impl Into<String>) -> Self
A Kind::Type error.
Sourcepub fn unique(message: impl Into<String>) -> Self
pub fn unique(message: impl Into<String>) -> Self
A Kind::Unique error.
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()