Skip to main content

Error

Enum Error 

Source
pub enum Error {
    Query {
        message: String,
        code: i64,
        previous: Option<Arc<dyn Error + Send + Sync>>,
        raw: Option<Arc<[u8]>>,
    },
    Validation(String),
    Unsupported(String),
    InvalidArgument(String),
    InvalidValue(String),
    Type(String),
    NoExecutor(String),
    Engine(String),
    Json {
        message: String,
        code: i64,
    },
}
Expand description

Why a query could not be parsed, validated or compiled.

PHP: one variant per exception class the library throws, with the same message (Error::php_class names the class).

Variants§

§

Query

A malformed query, or an error raised by Error::new.

PHP: Utopia\Query\Exception.

Fields

§message: String

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

§code: i64

The code (0 unless given to Error::new).

§previous: Option<Arc<dyn Error + Send + Sync>>

The error this one wraps.

§raw: Option<Arc<[u8]>>

The exact message, when it is not UTF-8 (a message quoting part of a multi-byte character of the input).

§

Validation(String)

An input the library refuses: an unsafe identifier, a missing table, an invalid option.

PHP: Utopia\Query\Exception\ValidationException.

§

Unsupported(String)

A feature the dialect cannot express.

PHP: Utopia\Query\Exception\UnsupportedException.

§

InvalidArgument(String)

An invalid constructor argument of a hook.

PHP: \InvalidArgumentException.

§

InvalidValue(String)

A name that is not one of an enumeration’s values.

PHP: \ValueError, from Method::from() and the other enums’ from().

§

Type(String)

An argument of the wrong type, where PHP’s type checks reject it (only where a Rust type cannot rule it out, such as a nested query that is not an array).

PHP: \TypeError.

§

NoExecutor(String)

A statement executed without an executor.

PHP: \BadMethodCallException.

§

Engine(String)

A value PHP’s engine cannot convert, such as an object in a string (Object of class stdClass could not be converted to string).

PHP: \Error.

§

Json

A value json_encode cannot encode (invalid UTF-8, a non-finite float), with the code PHP’s json_last_error() reports.

PHP: \JsonException.

Fields

§message: String

The message.

§code: i64

The JSON_ERROR_* code.

Implementations§

Source§

impl Error

Source

pub fn new(message: impl Into<String>, code: impl Into<Code>) -> Self

A Error::Query with message and code, as new Exception($message, $code).

use utopia_query::{Code, Error};

assert_eq!(Error::new("test", Code::from("42")).code(), 42);
assert_eq!(Error::new("test", Code::from("abc")).code(), 0);
use Utopia\Query\Exception;

echo (new Exception('test', '42'))->getCode(), "\n";  // 42
echo (new Exception('test', 'abc'))->getCode(), "\n"; // 0
Source

pub fn with_previous( message: impl Into<String>, code: impl Into<Code>, previous: Arc<dyn Error + Send + Sync>, ) -> Self

A Error::Query wrapping previous, as new Exception($message, $code, $previous).

Source

pub fn message_bytes(&self) -> Cow<'_, [u8]>

The message as PHP has it, byte for byte (to_string() is the same text, lossy where it is not UTF-8).

PHP: getMessage().

Source

pub fn code(&self) -> i64

The code: what Error::new was given, 0 for every error the library raises.

PHP: getCode().

Source

pub fn previous(&self) -> Option<&Arc<dyn Error + Send + Sync>>

The error this one wraps.

PHP: getPrevious().

Source

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

The name of the PHP exception class this error matches.

use utopia_query::Error;

assert_eq!(Error::Validation("x".into()).php_class(), "Utopia\\Query\\Exception\\ValidationException");
use Utopia\Query\Exception\ValidationException;

echo ValidationException::class, "\n"; // Utopia\Query\Exception\ValidationException
Source

pub fn is_query_exception(&self) -> bool

Whether PHP’s class for this error extends Utopia\Query\Exception (catching that class catches it).

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, __formatter: &mut Formatter<'_>) -> Result

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

impl Error for Error

1.30.0 · 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 PartialEq for Error

Source§

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

Same class, message and code.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Forget for Error

§

impl Freeze for Error
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const ArcInner<dyn Error + Sync + Send> is !null: Freeze, PhantomData<ArcInner<dyn Error + Sync + Send>>: Freeze, *const ArcInner<[u8]> is !null: Freeze, PhantomData<ArcInner<[u8]>>: Freeze,

§

impl Move for Error

§

impl Send for Error
where RawVecInner: Send, Arc<dyn Error + Sync + Send>: Send, Arc<[u8]>: Send,

§

impl Sync for Error
where RawVecInner: Sync, Arc<dyn Error + Sync + Send>: Sync, Arc<[u8]>: Sync,

§

impl Unpin for Error
where *const u8 is !null: Unpin, Arc<dyn Error + Sync + Send>: Unpin, Arc<[u8]>: Unpin,

§

impl UnsafeUnpin for Error
where *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const ArcInner<dyn Error + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Error + Sync + Send>>: UnsafeUnpin, *const ArcInner<[u8]> is !null: UnsafeUnpin, PhantomData<ArcInner<[u8]>>: UnsafeUnpin,

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.