1//! Errors, type aliases, and functions related to working with `Result`.
23use std::error::Erroras StdError;
4use std::ffi::NulError;
5use std::fmt::{self, Display};
67#[derive(#[automatically_derived]
#[allow(clippy::enum_variant_names)]
impl ::core::fmt::Debug for Error {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Error::InvalidCString(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"InvalidCString", &__self_0),
Error::DatabaseError(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"DatabaseError", __self_0, &__self_1),
Error::NotFound =>
::core::fmt::Formatter::write_str(f, "NotFound"),
Error::QueryBuilderError(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"QueryBuilderError", &__self_0),
Error::DeserializationError(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"DeserializationError", &__self_0),
Error::SerializationError(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"SerializationError", &__self_0),
Error::RollbackErrorOnCommit {
rollback_error: __self_0, commit_error: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"RollbackErrorOnCommit", "rollback_error", __self_0,
"commit_error", &__self_1),
Error::RollbackTransaction =>
::core::fmt::Formatter::write_str(f, "RollbackTransaction"),
Error::AlreadyInTransaction =>
::core::fmt::Formatter::write_str(f, "AlreadyInTransaction"),
Error::NotInTransaction =>
::core::fmt::Formatter::write_str(f, "NotInTransaction"),
Error::BrokenTransactionManager =>
::core::fmt::Formatter::write_str(f,
"BrokenTransactionManager"),
}
}
}Debug)]
8#[allow(clippy::enum_variant_names)]
9/// Represents all the ways that a query can fail.
10///
11/// This type is not intended to be exhaustively matched, and new variants may
12/// be added in the future without a major version bump.
13#[non_exhaustive]
14pub enum Error {
15/// The query contained a nul byte.
16 ///
17 /// This should never occur in normal usage.
18InvalidCString(NulError),
1920/// The database returned an error.
21 ///
22 /// While Diesel prevents almost all sources of runtime errors at compile
23 /// time, it does not attempt to prevent 100% of them. Typically this error
24 /// will occur from insert or update statements due to a constraint
25 /// violation.
26DatabaseError(
27DatabaseErrorKind,
28Box<dyn DatabaseErrorInformation + Send + Sync>,
29 ),
3031/// No rows were returned by a query expected to return at least one row.
32 ///
33 /// This variant is only returned by [`get_result`] and [`first`]. [`load`]
34 /// does not treat 0 rows as an error. If you would like to allow either 0
35 /// or 1 rows, call [`optional`] on the result.
36 ///
37 /// [`get_result`]: crate::query_dsl::RunQueryDsl::get_result()
38 /// [`first`]: crate::query_dsl::RunQueryDsl::first()
39 /// [`load`]: crate::query_dsl::RunQueryDsl::load()
40 /// [`optional`]: OptionalExtension::optional
41NotFound,
4243/// The query could not be constructed
44 ///
45 /// An example of when this error could occur is if you are attempting to
46 /// construct an update statement with no changes (e.g. all fields on the
47 /// struct are `None`).
48QueryBuilderError(Box<dyn StdError + Send + Sync>),
4950/// An error occurred deserializing the data being sent to the database.
51 ///
52 /// Typically this error means that the stated type of the query is
53 /// incorrect. An example of when this error might occur in normal usage is
54 /// attempting to deserialize an infinite date into chrono.
55DeserializationError(Box<dyn StdError + Send + Sync>),
5657/// An error occurred serializing the data being sent to the database.
58 ///
59 /// An example of when this error would be returned is if you attempted to
60 /// serialize a `chrono::NaiveDate` earlier than the earliest date supported
61 /// by PostgreSQL.
62SerializationError(Box<dyn StdError + Send + Sync>),
6364/// An error occurred when attempting rollback of a transaction subsequently to a failed
65 /// commit attempt.
66 ///
67 /// When a commit attempt fails and Diesel believes that it can attempt a rollback to return
68 /// the connection back in a usable state (out of that transaction), it attempts it then
69 /// returns the original error.
70 ///
71 /// If that fails, you get this.
72RollbackErrorOnCommit {
73/// The error that was encountered when attempting the rollback
74rollback_error: Box<Error>,
75/// The error that was encountered during the failed commit attempt
76commit_error: Box<Error>,
77 },
7879/// Roll back the current transaction.
80 ///
81 /// You can return this variant inside of a transaction when you want to
82 /// roll it back, but have no actual error to return. Diesel will never
83 /// return this variant unless you gave it to us, and it can be safely
84 /// ignored in error handling.
85RollbackTransaction,
8687/// Attempted to perform an operation that cannot be done inside a transaction
88 /// when a transaction was already open.
89AlreadyInTransaction,
9091/// Attempted to perform an operation that can only be done inside a transaction
92 /// when no transaction was open
93NotInTransaction,
9495/// Transaction manager broken, likely due to a broken connection. No other operations are possible.
96BrokenTransactionManager,
97}
9899#[derive(#[automatically_derived]
impl ::core::fmt::Debug for DatabaseErrorKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
DatabaseErrorKind::UniqueViolation => "UniqueViolation",
DatabaseErrorKind::ForeignKeyViolation =>
"ForeignKeyViolation",
DatabaseErrorKind::UnableToSendCommand =>
"UnableToSendCommand",
DatabaseErrorKind::SerializationFailure =>
"SerializationFailure",
DatabaseErrorKind::ReadOnlyTransaction =>
"ReadOnlyTransaction",
DatabaseErrorKind::RestrictViolation => "RestrictViolation",
DatabaseErrorKind::NotNullViolation => "NotNullViolation",
DatabaseErrorKind::CheckViolation => "CheckViolation",
DatabaseErrorKind::ExclusionViolation => "ExclusionViolation",
DatabaseErrorKind::ClosedConnection => "ClosedConnection",
DatabaseErrorKind::Unknown => "Unknown",
})
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for DatabaseErrorKind {
#[inline]
fn eq(&self, other: &DatabaseErrorKind) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::clone::Clone for DatabaseErrorKind {
#[inline]
fn clone(&self) -> DatabaseErrorKind { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for DatabaseErrorKind { }Copy)]
100/// The kind of database error that occurred.
101///
102/// This is not meant to exhaustively cover all possible errors, but is used to
103/// identify errors which are commonly recovered from programmatically. This enum
104/// is not intended to be exhaustively matched, and new variants may be added in
105/// the future without a major version bump.
106#[non_exhaustive]
107pub enum DatabaseErrorKind {
108/// A unique constraint was violated.
109UniqueViolation = 0,
110111/// A foreign key constraint was violated.
112ForeignKeyViolation = 1,
113114/// The query could not be sent to the database due to a protocol violation.
115 ///
116 /// An example of a case where this would occur is if you attempted to send
117 /// a query with more than 65000 bind parameters using PostgreSQL.
118UnableToSendCommand = 2,
119120/// A serializable transaction failed to commit due to a read/write
121 /// dependency on a concurrent transaction.
122 ///
123 /// Corresponds to SQLSTATE code 40001
124 ///
125 /// This error is only detected for PostgreSQL, as we do not yet support
126 /// transaction isolation levels for other backends.
127SerializationFailure = 3,
128129/// The command could not be completed because the transaction was read
130 /// only.
131 ///
132 /// This error will also be returned for `SELECT` statements which attempted
133 /// to lock the rows.
134ReadOnlyTransaction = 4,
135136/// A restrict constraint was violated.
137RestrictViolation = 9,
138139/// A not null constraint was violated.
140NotNullViolation = 5,
141142/// A check constraint was violated.
143CheckViolation = 6,
144145/// An exclusion constraint was violated.
146ExclusionViolation = 10,
147148/// The connection to the server was unexpectedly closed.
149 ///
150 /// This error is only detected for PostgreSQL and is emitted on a best-effort basis
151 /// and may be missed.
152ClosedConnection = 7,
153154#[doc(hidden)]
155Unknown = 8, // Match against _ instead, more variants may be added in the future
156}
157158/// Information about an error that was returned by the database.
159pub trait DatabaseErrorInformation {
160/// The primary human-readable error message. Typically one line.
161fn message(&self) -> &str;
162163/// An optional secondary error message providing more details about the
164 /// problem, if it was provided by the database. Might span multiple lines.
165fn details(&self) -> Option<&str>;
166167/// An optional suggestion of what to do about the problem, if one was
168 /// provided by the database.
169fn hint(&self) -> Option<&str>;
170171/// The name of the table the error was associated with, if the error was
172 /// associated with a specific table and the backend supports retrieving
173 /// that information.
174 ///
175 /// Currently this method will return `None` for all backends other than
176 /// PostgreSQL.
177fn table_name(&self) -> Option<&str>;
178179/// The name of the column the error was associated with, if the error was
180 /// associated with a specific column and the backend supports retrieving
181 /// that information.
182 ///
183 /// Currently this method will return `None` for all backends other than
184 /// PostgreSQL.
185fn column_name(&self) -> Option<&str>;
186187/// The constraint that was violated if this error is a constraint violation
188 /// and the backend supports retrieving that information.
189 ///
190 /// Currently this method will return `None` for all backends other than
191 /// PostgreSQL.
192fn constraint_name(&self) -> Option<&str>;
193194/// An optional integer indicating an error cursor position as an index into
195 /// the original statement string.
196fn statement_position(&self) -> Option<i32>;
197}
198199impl fmt::Debugfor dyn DatabaseErrorInformation + Send + Sync {
200fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
201 fmt::Debug::fmt(&self.message(), f)
202 }
203}
204205impl DatabaseErrorInformationfor String {
206fn message(&self) -> &str {
207self208 }
209fn details(&self) -> Option<&str> {
210None211 }
212fn hint(&self) -> Option<&str> {
213None214 }
215fn table_name(&self) -> Option<&str> {
216None217 }
218fn column_name(&self) -> Option<&str> {
219None220 }
221fn constraint_name(&self) -> Option<&str> {
222None223 }
224fn statement_position(&self) -> Option<i32> {
225None226 }
227}
228229/// Errors which can occur during [`Connection::establish`]
230///
231/// [`Connection::establish`]: crate::connection::Connection::establish
232#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ConnectionError {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ConnectionError::InvalidCString(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"InvalidCString", &__self_0),
ConnectionError::BadConnection(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"BadConnection", &__self_0),
ConnectionError::InvalidConnectionUrl(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"InvalidConnectionUrl", &__self_0),
ConnectionError::CouldntSetupConfiguration(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"CouldntSetupConfiguration", &__self_0),
}
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for ConnectionError {
#[inline]
fn eq(&self, other: &ConnectionError) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(ConnectionError::InvalidCString(__self_0),
ConnectionError::InvalidCString(__arg1_0)) =>
__self_0 == __arg1_0,
(ConnectionError::BadConnection(__self_0),
ConnectionError::BadConnection(__arg1_0)) =>
__self_0 == __arg1_0,
(ConnectionError::InvalidConnectionUrl(__self_0),
ConnectionError::InvalidConnectionUrl(__arg1_0)) =>
__self_0 == __arg1_0,
(ConnectionError::CouldntSetupConfiguration(__self_0),
ConnectionError::CouldntSetupConfiguration(__arg1_0)) =>
__self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq)]
233#[non_exhaustive]
234pub enum ConnectionError {
235/// The connection URL contained a `NUL` byte.
236InvalidCString(NulError),
237/// The database returned an error.
238BadConnection(String),
239/// The connection URL could not be parsed.
240InvalidConnectionUrl(String),
241/// Diesel could not configure the database connection.
242 ///
243 /// Diesel may try to automatically set session specific configuration
244 /// values, such as UTF8 encoding, or enabling the `||` operator on MySQL.
245 /// This variant is returned if an error occurred executing the query to set
246 /// those options. Diesel will never affect global configuration.
247CouldntSetupConfiguration(Error),
248}
249250/// A specialized result type for queries.
251///
252/// This type is exported by `diesel::prelude`, and is generally used by any
253/// code which is interacting with Diesel. This type exists to avoid writing out
254/// `diesel::result::Error`, and is otherwise a direct mapping to `Result`.
255pub type QueryResult<T> = Result<T, Error>;
256257/// A specialized result type for establishing connections.
258///
259/// This type exists to avoid writing out `diesel::result::ConnectionError`, and
260/// is otherwise a direct mapping to `Result`.
261pub type ConnectionResult<T> = Result<T, ConnectionError>;
262263/// See the [method documentation](OptionalExtension::optional).
264pub trait OptionalExtension<T> {
265/// Converts a `QueryResult<T>` into a `QueryResult<Option<T>>`.
266 ///
267 /// By default, Diesel treats 0 rows being returned from a query that is expected to return 1
268 /// row as an error (e.g. the return value of [`get_result`] or [`first`]). This method will
269 /// handle that error, and give you back an `Option<T>` instead.
270 ///
271 /// [`get_result`]: crate::query_dsl::RunQueryDsl::get_result()
272 /// [`first`]: crate::query_dsl::RunQueryDsl::first()
273 ///
274 /// # Example
275 ///
276 /// ```rust
277 /// use diesel::{NotFound, OptionalExtension, QueryResult};
278 ///
279 /// let result: QueryResult<i32> = Ok(1);
280 /// assert_eq!(Ok(Some(1)), result.optional());
281 ///
282 /// let result: QueryResult<i32> = Err(NotFound);
283 /// assert_eq!(Ok(None), result.optional());
284 /// ```
285fn optional(self) -> Result<Option<T>, Error>;
286}
287288impl<T> OptionalExtension<T> for QueryResult<T> {
289fn optional(self) -> Result<Option<T>, Error> {
290match self {
291Ok(value) => Ok(Some(value)),
292Err(Error::NotFound) => Ok(None),
293Err(e) => Err(e),
294 }
295 }
296}
297298/// See the [method documentation](OptionalEmptyChangesetExtension::optional_empty_changeset).
299pub trait OptionalEmptyChangesetExtension<T> {
300/// By default, Diesel treats an empty update as a `QueryBuilderError`. This method will
301 /// convert that error into `None`.
302 ///
303 /// # Example
304 ///
305 /// ```rust
306 /// use diesel::{
307 /// result::EmptyChangeset, result::Error::QueryBuilderError, OptionalEmptyChangesetExtension,
308 /// QueryResult,
309 /// };
310 /// let result: QueryResult<i32> = Err(QueryBuilderError(Box::new(EmptyChangeset)));
311 /// assert_eq!(Ok(None), result.optional_empty_changeset());
312 /// ```
313fn optional_empty_changeset(self) -> Result<Option<T>, Error>;
314}
315316impl<T> OptionalEmptyChangesetExtension<T> for QueryResult<T> {
317fn optional_empty_changeset(self) -> Result<Option<T>, Error> {
318match self {
319Ok(value) => Ok(Some(value)),
320Err(Error::QueryBuilderError(e)) if e.is::<EmptyChangeset>() => Ok(None),
321Err(e) => Err(e),
322 }
323 }
324}
325326impl From<NulError> for ConnectionError {
327fn from(e: NulError) -> Self {
328 ConnectionError::InvalidCString(e)
329 }
330}
331332impl From<NulError> for Error {
333fn from(e: NulError) -> Self {
334 Error::InvalidCString(e)
335 }
336}
337338impl Displayfor Error {
339fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
340match *self{
341 Error::InvalidCString(ref nul_err) => f.write_fmt(format_args!("{0}", nul_err))write!(f, "{nul_err}"),
342 Error::DatabaseError(_, ref e) => f.write_fmt(format_args!("{0}", e.message()))write!(f, "{}", e.message()),
343 Error::NotFound => f.write_str("Record not found"),
344 Error::QueryBuilderError(ref e) => e.fmt(f),
345 Error::DeserializationError(ref e) => e.fmt(f),
346 Error::SerializationError(ref e) => e.fmt(f),
347 Error::RollbackErrorOnCommit {
348ref rollback_error,
349ref commit_error,
350 } => {
351f.write_fmt(format_args!("Transaction rollback failed: {0} (rollback attempted because of failure to commit: {1})",
&**rollback_error, &**commit_error))write!(
352f,
353"Transaction rollback failed: {} \
354 (rollback attempted because of failure to commit: {})",
355&**rollback_error, &**commit_error
356 )?;
357Ok(())
358 }
359 Error::RollbackTransaction => {
360f.write_fmt(format_args!("You have asked diesel to rollback the transaction"))write!(f, "You have asked diesel to rollback the transaction")361 }
362 Error::BrokenTransactionManager => f.write_fmt(format_args!("The transaction manager is broken"))write!(f, "The transaction manager is broken"),
363 Error::AlreadyInTransaction => f.write_fmt(format_args!("Cannot perform this operation while a transaction is open"))write!(
364f,
365"Cannot perform this operation while a transaction is open",
366 ),
367 Error::NotInTransaction => {
368f.write_fmt(format_args!("Cannot perform this operation outside of a transaction"))write!(f, "Cannot perform this operation outside of a transaction",)369 }
370 }
371 }
372}
373374impl StdErrorfor Error {
375fn cause(&self) -> Option<&dyn StdError> {
376match *self{
377 Error::InvalidCString(ref e) => Some(e),
378 Error::QueryBuilderError(ref e) => Some(&**e),
379 Error::DeserializationError(ref e) => Some(&**e),
380 Error::SerializationError(ref e) => Some(&**e),
381_ => None,
382 }
383 }
384}
385386impl Displayfor ConnectionError {
387fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
388match *self{
389 ConnectionError::InvalidCString(ref nul_err) => nul_err.fmt(f),
390 ConnectionError::BadConnection(ref s) => f.write_fmt(format_args!("{0}", s))write!(f, "{s}"),
391 ConnectionError::InvalidConnectionUrl(ref s) => f.write_fmt(format_args!("{0}", s))write!(f, "{s}"),
392 ConnectionError::CouldntSetupConfiguration(ref e) => e.fmt(f),
393 }
394 }
395}
396397impl StdErrorfor ConnectionError {
398fn cause(&self) -> Option<&dyn StdError> {
399match *self{
400 ConnectionError::InvalidCString(ref e) => Some(e),
401 ConnectionError::CouldntSetupConfiguration(ref e) => Some(e),
402_ => None,
403 }
404 }
405}
406407impl PartialEqfor Error {
408fn eq(&self, other: &Error) -> bool {
409match (self, other) {
410 (Error::InvalidCString(a), Error::InvalidCString(b)) => a == b,
411 (Error::DatabaseError(_, a), Error::DatabaseError(_, b)) => a.message() == b.message(),
412 (&Error::NotFound, &Error::NotFound) => true,
413 (&Error::RollbackTransaction, &Error::RollbackTransaction) => true,
414 (&Error::AlreadyInTransaction, &Error::AlreadyInTransaction) => true,
415_ => false,
416 }
417 }
418}
419420#[cfg(test)]
421#[allow(warnings)]
422fn error_impls_send() {
423let err: Error = unimplemented!();
424let x: &dyn Send = &err;
425}
426427/// An unexpected `NULL` was encountered during deserialization
428#[derive(#[automatically_derived]
impl ::core::fmt::Debug for UnexpectedNullError {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f, "UnexpectedNullError")
}
}Debug, #[automatically_derived]
impl ::core::clone::Clone for UnexpectedNullError {
#[inline]
fn clone(&self) -> UnexpectedNullError { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for UnexpectedNullError { }Copy)]
429pub struct UnexpectedNullError;
430431impl fmt::Displayfor UnexpectedNullError {
432fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
433f.write_fmt(format_args!("Unexpected null for non-null column"))write!(f, "Unexpected null for non-null column")434 }
435}
436437impl StdErrorfor UnexpectedNullError {}
438439/// Expected more fields then present in the current row while deserializing results
440#[derive(#[automatically_derived]
impl ::core::fmt::Debug for UnexpectedEndOfRow {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f, "UnexpectedEndOfRow")
}
}Debug, #[automatically_derived]
impl ::core::clone::Clone for UnexpectedEndOfRow {
#[inline]
fn clone(&self) -> UnexpectedEndOfRow { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for UnexpectedEndOfRow { }Copy)]
441pub struct UnexpectedEndOfRow;
442443impl fmt::Displayfor UnexpectedEndOfRow {
444fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
445f.write_fmt(format_args!("Unexpected end of row"))write!(f, "Unexpected end of row")446 }
447}
448449impl StdErrorfor UnexpectedEndOfRow {}
450451/// Expected when an update has no changes to save.
452///
453/// When using `optional_empty_changeset`, this error is turned into `None`.
454#[derive(#[automatically_derived]
impl ::core::fmt::Debug for EmptyChangeset {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f, "EmptyChangeset")
}
}Debug, #[automatically_derived]
impl ::core::clone::Clone for EmptyChangeset {
#[inline]
fn clone(&self) -> EmptyChangeset { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for EmptyChangeset { }Copy)]
455pub struct EmptyChangeset;
456457impl fmt::Displayfor EmptyChangeset {
458fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
459f.write_fmt(format_args!("There are no changes to save. This query cannot be built"))write!(
460f,
461"There are no changes to save. This query cannot be built"
462)463 }
464}
465466impl StdErrorfor EmptyChangeset {}
467468/// Expected when you try to execute an empty query
469#[derive(#[automatically_derived]
impl ::core::fmt::Debug for EmptyQuery {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f, "EmptyQuery")
}
}Debug, #[automatically_derived]
impl ::core::clone::Clone for EmptyQuery {
#[inline]
fn clone(&self) -> EmptyQuery { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for EmptyQuery { }Copy)]
470pub struct EmptyQuery;
471472impl fmt::Displayfor EmptyQuery {
473fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
474f.write_fmt(format_args!("Detected an empty query. These are not supported by your database system"))write!(
475f,
476"Detected an empty query. These are not supported by your database system"
477)478 }
479}
480481impl StdErrorfor EmptyQuery {}
482483/// An error occurred while deserializing a field
484#[derive(#[automatically_derived]
impl ::core::fmt::Debug for DeserializeFieldError {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"DeserializeFieldError", "field_name", &self.field_name, "error",
&&self.error)
}
}Debug)]
485#[non_exhaustive]
486pub struct DeserializeFieldError {
487/// The name of the field that failed to deserialize
488pub field_name: Option<String>,
489/// The error that occurred while deserializing the field
490pub error: Box<dyn StdError + Send + Sync>,
491}
492493impl DeserializeFieldError {
494#[cold]
495pub(crate) fn new<'a, F, DB>(field: F, error: Box<dyn std::error::Error + Send + Sync>) -> Self
496where
497DB: crate::backend::Backend,
498 F: crate::row::Field<'a, DB>,
499 {
500DeserializeFieldError {
501 field_name: field.field_name().map(|s| s.to_string()),
502error,
503 }
504 }
505}
506507impl StdErrorfor DeserializeFieldError {
508fn source(&self) -> Option<&(dyn StdError + 'static)> {
509Some(&*self.error)
510 }
511}
512513impl fmt::Displayfor DeserializeFieldError {
514fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
515if let Some(ref field_name) = self.field_name {
516f.write_fmt(format_args!("Error deserializing field \'{0}\': {1}", field_name,
self.error))write!(
517f,
518"Error deserializing field '{}': {}",
519 field_name, self.error
520 )521 } else {
522f.write_fmt(format_args!("Error deserializing field: {0}", self.error))write!(f, "Error deserializing field: {}", self.error)523 }
524 }
525}