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: StringThe message (lossy when Error::message_bytes is not UTF-8).
code: i64The code (0 unless given to Error::new).
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.
Implementations§
Source§impl Error
impl Error
Sourcepub fn new(message: impl Into<String>, code: impl Into<Code>) -> Self
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"; // 0Sourcepub fn with_previous(
message: impl Into<String>,
code: impl Into<Code>,
previous: Arc<dyn Error + Send + Sync>,
) -> Self
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).
Sourcepub fn message_bytes(&self) -> Cow<'_, [u8]>
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().
Sourcepub fn code(&self) -> i64
pub fn code(&self) -> i64
The code: what Error::new was given, 0 for every error the library raises.
PHP: getCode().
Sourcepub fn previous(&self) -> Option<&Arc<dyn Error + Send + Sync>>
pub fn previous(&self) -> Option<&Arc<dyn Error + Send + Sync>>
The error this one wraps.
PHP: getPrevious().
Sourcepub fn php_class(&self) -> &'static str
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\ValidationExceptionSourcepub fn is_query_exception(&self) -> bool
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 Error for Error
impl Error for Error
1.30.0 · 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()