Skip to main content

Error

Struct Error 

Source
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

Source

pub fn new(kind: Kind, message: impl Into<String>) -> Self

An error of kind with message and code 0.

Source

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).

Source

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.

Source

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).

Source

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.

Source

pub fn state(&self) -> Option<&str>

The string code the error was built with, such as a SQLSTATE ($state); None for an integer code.

Source

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.

Source

pub fn driver_code(&self) -> Option<i64>

The driver’s own error code ($errorInfo[1]), when the error carries one.

Source

pub fn with_labels(self, labels: Vec<String>) -> Self

The same error with the server’s error labels (a MongoDB error’s TransientTransactionError, UnknownTransactionCommitResult, …).

Source

pub fn labels(&self) -> &[String]

The server’s error labels (getErrorLabels()); empty when the error carries none.

Source

pub fn with_previous(self, previous: Error) -> Self

The same error wrapping previous.

Source

pub fn order(message: impl Into<String>, attribute: Option<String>) -> Self

An Kind::Order error about attribute.

Source

pub fn kind(&self) -> Kind

The kind (PHP class) of the error.

Source

pub fn php_class(&self) -> &'static str

The PHP class of the error.

Source

pub fn is_a(&self, kind: Kind) -> bool

Whether the error is of kind or of a kind extending it (instanceof).

Source

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.

Source

pub fn message(&self) -> &str

The message (getMessage()), lossy when Error::message_bytes is not UTF-8.

Source

pub fn message_bytes(&self) -> &[u8] ⓘ

The message (getMessage()) byte for byte.

Source

pub fn code(&self) -> i64

The code (getCode()).

Source

pub fn attribute(&self) -> Option<&str>

The attribute of an Kind::Order error (getAttribute()).

Source

pub fn previous(&self) -> Option<&Error>

The wrapped error (getPrevious()).

Source§

impl Error

Source

pub fn database(message: impl Into<String>) -> Self

A Kind::Database error.

Source

pub fn authorization(message: impl Into<String>) -> Self

Source

pub fn schema(message: impl Into<String>) -> Self

A Kind::Schema error.

Source

pub fn contention(message: impl Into<String>) -> Self

Source

pub fn mismatch(message: impl Into<String>) -> Self

A Kind::Mismatch error.

Source

pub fn refused(message: impl Into<String>) -> Self

A Kind::Refused error.

Source

pub fn unconfirmed(message: impl Into<String>) -> Self

Source

pub fn exception(message: impl Into<String>) -> Self

A Kind::Exception error.

Source

pub fn character(message: impl Into<String>) -> Self

A Kind::Character error.

Source

pub fn conflict(message: impl Into<String>) -> Self

A Kind::Conflict error.

Source

pub fn dependency(message: impl Into<String>) -> Self

Source

pub fn duplicate(message: impl Into<String>) -> Self

A Kind::Duplicate error.

Source

pub fn index(message: impl Into<String>) -> Self

A Kind::Index error.

Source

pub fn limit(message: impl Into<String>) -> Self

A Kind::Limit error.

Source

pub fn not_found(message: impl Into<String>) -> Self

A Kind::NotFound error.

Source

pub fn operator(message: impl Into<String>) -> Self

A Kind::Operator error.

Source

pub fn query(message: impl Into<String>) -> Self

A Kind::Query error.

Source

pub fn relationship(message: impl Into<String>) -> Self

Source

pub fn restricted(message: impl Into<String>) -> Self

Source

pub fn structure(message: impl Into<String>) -> Self

A Kind::Structure error.

Source

pub fn timeout(message: impl Into<String>) -> Self

A Kind::Timeout error.

Source

pub fn transaction(message: impl Into<String>) -> Self

Source

pub fn truncate(message: impl Into<String>) -> Self

A Kind::Truncate error.

Source

pub fn type_error(message: impl Into<String>) -> Self

A Kind::Type error.

Source

pub fn unique(message: impl Into<String>) -> Self

A Kind::Unique error.

Trait Implementations§

Source§

impl Clone for Error

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Replaced by Error::source.
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<EngineError> for Error

Source§

fn from(e: EngineError) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Error

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Error

Auto Trait Implementations§

§

impl Forget for Error

§

impl Freeze for Error

§

impl Move 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.