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 {
Self::InvalidCString(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"InvalidCString", &__self_0),
Self::DatabaseError(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"DatabaseError", __self_0, &__self_1),
Self::NotFound =>
::core::fmt::Formatter::write_str(f, "NotFound"),
Self::QueryBuilderError(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"QueryBuilderError", &__self_0),
Self::DeserializationError(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"DeserializationError", &__self_0),
Self::SerializationError(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"SerializationError", &__self_0),
Self::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),
Self::RollbackTransaction =>
::core::fmt::Formatter::write_str(f, "RollbackTransaction"),
Self::AlreadyInTransaction =>
::core::fmt::Formatter::write_str(f, "AlreadyInTransaction"),
Self::NotInTransaction =>
::core::fmt::Formatter::write_str(f, "NotInTransaction"),
Self::BrokenTransactionManager =>
::core::fmt::Formatter::write_str(f,
"BrokenTransactionManager"),
Self::IntegerConversion(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"IntegerConversion", &__self_0),
}
}
}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,
9798/// Internal integer conversion failed
99IntegerConversion(core::num::TryFromIntError),
100}
101102#[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::marker::StructuralPartialEq for DatabaseErrorKind { }
#[automatically_derived]
impl ::core::cmp::PartialEq for DatabaseErrorKind {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for DatabaseErrorKind { }
#[automatically_derived]
impl ::core::clone::Clone for DatabaseErrorKind {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for DatabaseErrorKind { }Copy)]
103/// The kind of database error that occurred.
104///
105/// This is not meant to exhaustively cover all possible errors, but is used to
106/// identify errors which are commonly recovered from programmatically. This enum
107/// is not intended to be exhaustively matched, and new variants may be added in
108/// the future without a major version bump.
109#[non_exhaustive]
110pub enum DatabaseErrorKind {
111/// A unique constraint was violated.
112UniqueViolation = 0,
113114/// A foreign key constraint was violated.
115ForeignKeyViolation = 1,
116117/// The query could not be sent to the database due to a protocol violation.
118 ///
119 /// An example of a case where this would occur is if you attempted to send
120 /// a query with more than 65000 bind parameters using PostgreSQL.
121UnableToSendCommand = 2,
122123/// A serializable transaction failed to commit due to a read/write
124 /// dependency on a concurrent transaction.
125 ///
126 /// Corresponds to SQLSTATE code 40001
127 ///
128 /// This error is only detected for PostgreSQL, as we do not yet support
129 /// transaction isolation levels for other backends.
130SerializationFailure = 3,
131132/// The command could not be completed because the transaction was read
133 /// only.
134 ///
135 /// This error will also be returned for `SELECT` statements which attempted
136 /// to lock the rows.
137ReadOnlyTransaction = 4,
138139/// A restrict constraint was violated.
140RestrictViolation = 9,
141142/// A not null constraint was violated.
143NotNullViolation = 5,
144145/// A check constraint was violated.
146CheckViolation = 6,
147148/// An exclusion constraint was violated.
149ExclusionViolation = 10,
150151/// The connection to the server was unexpectedly closed.
152 ///
153 /// This error is only detected for PostgreSQL and is emitted on a best-effort basis
154 /// and may be missed.
155ClosedConnection = 7,
156157#[doc(hidden)]
158Unknown = 8, // Match against _ instead, more variants may be added in the future
159}
160161/// Information about an error that was returned by the database.
162pub trait DatabaseErrorInformation {
163/// The primary human-readable error message. Typically one line.
164fn message(&self) -> &str;
165166/// An optional secondary error message providing more details about the
167 /// problem, if it was provided by the database. Might span multiple lines.
168fn details(&self) -> Option<&str>;
169170/// An optional suggestion of what to do about the problem, if one was
171 /// provided by the database.
172fn hint(&self) -> Option<&str>;
173174/// The name of the table the error was associated with, if the error was
175 /// associated with a specific table and the backend supports retrieving
176 /// that information.
177 ///
178 /// Currently this method will return `None` for all backends other than
179 /// PostgreSQL.
180fn table_name(&self) -> Option<&str>;
181182/// The name of the column the error was associated with, if the error was
183 /// associated with a specific column and the backend supports retrieving
184 /// that information.
185 ///
186 /// Currently this method will return `None` for all backends other than
187 /// PostgreSQL.
188fn column_name(&self) -> Option<&str>;
189190/// The constraint that was violated if this error is a constraint violation
191 /// and the backend supports retrieving that information.
192 ///
193 /// Currently this method will return `None` for all backends other than
194 /// PostgreSQL.
195fn constraint_name(&self) -> Option<&str>;
196197/// An optional integer indicating an error cursor position as an index into
198 /// the original statement string.
199fn statement_position(&self) -> Option<i32>;
200}
201202impl fmt::Debugfor dyn DatabaseErrorInformation + Send + Sync {
203fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
204 fmt::Debug::fmt(&self.message(), f)
205 }
206}
207208impl DatabaseErrorInformationfor String {
209fn message(&self) -> &str {
210self211 }
212fn details(&self) -> Option<&str> {
213None214 }
215fn hint(&self) -> Option<&str> {
216None217 }
218fn table_name(&self) -> Option<&str> {
219None220 }
221fn column_name(&self) -> Option<&str> {
222None223 }
224fn constraint_name(&self) -> Option<&str> {
225None226 }
227fn statement_position(&self) -> Option<i32> {
228None229 }
230}
231232/// Errors which can occur during [`Connection::establish`]
233///
234/// [`Connection::establish`]: crate::connection::Connection::establish
235#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ConnectionError {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::InvalidCString(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"InvalidCString", &__self_0),
Self::BadConnection(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"BadConnection", &__self_0),
Self::InvalidConnectionUrl(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"InvalidConnectionUrl", &__self_0),
Self::CouldntSetupConfiguration(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"CouldntSetupConfiguration", &__self_0),
}
}
}Debug, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for ConnectionError { }
#[automatically_derived]
impl ::core::cmp::PartialEq for ConnectionError {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::InvalidCString(__self_0),
Self::InvalidCString(__arg1_0)) => __self_0 == __arg1_0,
(Self::BadConnection(__self_0), Self::BadConnection(__arg1_0))
=> __self_0 == __arg1_0,
(Self::InvalidConnectionUrl(__self_0),
Self::InvalidConnectionUrl(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::CouldntSetupConfiguration(__self_0),
Self::CouldntSetupConfiguration(__arg1_0)) =>
__self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq)]
236#[non_exhaustive]
237pub enum ConnectionError {
238/// The connection URL contained a `NUL` byte.
239InvalidCString(NulError),
240/// The database returned an error.
241BadConnection(String),
242/// The connection URL could not be parsed.
243InvalidConnectionUrl(String),
244/// Diesel could not configure the database connection.
245 ///
246 /// Diesel may try to automatically set session specific configuration
247 /// values, such as UTF8 encoding, or enabling the `||` operator on MySQL.
248 /// This variant is returned if an error occurred executing the query to set
249 /// those options. Diesel will never affect global configuration.
250CouldntSetupConfiguration(Error),
251}
252253/// A specialized result type for queries.
254///
255/// This type is exported by `diesel::prelude`, and is generally used by any
256/// code which is interacting with Diesel. This type exists to avoid writing out
257/// `diesel::result::Error`, and is otherwise a direct mapping to `Result`.
258pub type QueryResult<T> = Result<T, Error>;
259260/// A specialized result type for establishing connections.
261///
262/// This type exists to avoid writing out `diesel::result::ConnectionError`, and
263/// is otherwise a direct mapping to `Result`.
264pub type ConnectionResult<T> = Result<T, ConnectionError>;
265266/// See the [method documentation](OptionalExtension::optional).
267pub trait OptionalExtension<T> {
268/// Converts a `QueryResult<T>` into a `QueryResult<Option<T>>`.
269 ///
270 /// By default, Diesel treats 0 rows being returned from a query that is expected to return 1
271 /// row as an error (e.g. the return value of [`get_result`] or [`first`]). This method will
272 /// handle that error, and give you back an `Option<T>` instead.
273 ///
274 /// [`get_result`]: crate::query_dsl::RunQueryDsl::get_result()
275 /// [`first`]: crate::query_dsl::RunQueryDsl::first()
276 ///
277 /// # Example
278 ///
279 /// ```rust
280 /// use diesel::{NotFound, OptionalExtension, QueryResult};
281 ///
282 /// let result: QueryResult<i32> = Ok(1);
283 /// assert_eq!(Ok(Some(1)), result.optional());
284 ///
285 /// let result: QueryResult<i32> = Err(NotFound);
286 /// assert_eq!(Ok(None), result.optional());
287 /// ```
288fn optional(self) -> Result<Option<T>, Error>;
289}
290291impl<T> OptionalExtension<T> for QueryResult<T> {
292fn optional(self) -> Result<Option<T>, Error> {
293match self {
294Ok(value) => Ok(Some(value)),
295Err(Error::NotFound) => Ok(None),
296Err(e) => Err(e),
297 }
298 }
299}
300301/// See the [method documentation](OptionalEmptyChangesetExtension::optional_empty_changeset).
302pub trait OptionalEmptyChangesetExtension<T> {
303/// By default, Diesel treats an empty update as a `QueryBuilderError`. This method will
304 /// convert that error into `None`.
305 ///
306 /// # Example
307 ///
308 /// ```rust
309 /// use diesel::{
310 /// result::EmptyChangeset, result::Error::QueryBuilderError, OptionalEmptyChangesetExtension,
311 /// QueryResult,
312 /// };
313 /// let result: QueryResult<i32> = Err(QueryBuilderError(Box::new(EmptyChangeset)));
314 /// assert_eq!(Ok(None), result.optional_empty_changeset());
315 /// ```
316fn optional_empty_changeset(self) -> Result<Option<T>, Error>;
317}
318319impl<T> OptionalEmptyChangesetExtension<T> for QueryResult<T> {
320fn optional_empty_changeset(self) -> Result<Option<T>, Error> {
321match self {
322Ok(value) => Ok(Some(value)),
323Err(Error::QueryBuilderError(e)) if e.is::<EmptyChangeset>() => Ok(None),
324Err(e) => Err(e),
325 }
326 }
327}
328329impl From<NulError> for ConnectionError {
330fn from(e: NulError) -> Self {
331 ConnectionError::InvalidCString(e)
332 }
333}
334335impl From<NulError> for Error {
336fn from(e: NulError) -> Self {
337 Error::InvalidCString(e)
338 }
339}
340341impl Displayfor Error {
342fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
343match *self {
344 Error::InvalidCString(ref nul_err) => f.write_fmt(format_args!("{0}", nul_err))write!(f, "{nul_err}"),
345 Error::DatabaseError(_, ref e) => f.write_fmt(format_args!("{0}", e.message()))write!(f, "{}", e.message()),
346 Error::NotFound => f.write_str("Record not found"),
347 Error::QueryBuilderError(ref e) => e.fmt(f),
348 Error::DeserializationError(ref e) => e.fmt(f),
349 Error::SerializationError(ref e) => e.fmt(f),
350 Error::RollbackErrorOnCommit {
351ref rollback_error,
352ref commit_error,
353 } => {
354f.write_fmt(format_args!("Transaction rollback failed: {0} (rollback attempted because of failure to commit: {1})",
rollback_error, commit_error))write!(
355 f,
356"Transaction rollback failed: {rollback_error} \
357 (rollback attempted because of failure to commit: {commit_error})",
358 )?;
359Ok(())
360 }
361 Error::RollbackTransaction => {
362f.write_fmt(format_args!("You have asked diesel to rollback the transaction"))write!(f, "You have asked diesel to rollback the transaction")363 }
364 Error::BrokenTransactionManager => f.write_fmt(format_args!("The transaction manager is broken"))write!(f, "The transaction manager is broken"),
365 Error::AlreadyInTransaction => f.write_fmt(format_args!("Cannot perform this operation while a transaction is open"))write!(
366f,
367"Cannot perform this operation while a transaction is open",
368 ),
369 Error::NotInTransaction => {
370f.write_fmt(format_args!("Cannot perform this operation outside of a transaction"))write!(f, "Cannot perform this operation outside of a transaction",)371 }
372 Error::IntegerConversion(_) => f.write_str("Internal integer conversion failed"),
373 }
374 }
375}
376377impl StdErrorfor Error {
378fn source(&self) -> Option<&(dyn StdError + 'static)> {
379match *self {
380 Error::InvalidCString(ref e) => e.source(),
381 Error::QueryBuilderError(ref e) => e.source(),
382 Error::DeserializationError(ref e) => e.source(),
383 Error::SerializationError(ref e) => e.source(),
384 Error::IntegerConversion(ref e) => Some(e),
385_ => None,
386 }
387 }
388}
389390impl Displayfor ConnectionError {
391fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
392match *self {
393 ConnectionError::InvalidCString(ref nul_err) => nul_err.fmt(f),
394 ConnectionError::BadConnection(ref s) => f.write_fmt(format_args!("{0}", s))write!(f, "{s}"),
395 ConnectionError::InvalidConnectionUrl(ref s) => f.write_fmt(format_args!("{0}", s))write!(f, "{s}"),
396 ConnectionError::CouldntSetupConfiguration(ref e) => e.fmt(f),
397 }
398 }
399}
400401impl StdErrorfor ConnectionError {
402fn source(&self) -> Option<&(dyn StdError + 'static)> {
403match *self {
404 ConnectionError::InvalidCString(ref e) => e.source(),
405 ConnectionError::CouldntSetupConfiguration(ref e) => e.source(),
406_ => None,
407 }
408 }
409}
410411impl PartialEqfor Error {
412fn eq(&self, other: &Error) -> bool {
413match (self, other) {
414 (Error::InvalidCString(a), Error::InvalidCString(b)) => a == b,
415 (Error::DatabaseError(_, a), Error::DatabaseError(_, b)) => a.message() == b.message(),
416 (&Error::NotFound, &Error::NotFound) => true,
417 (&Error::RollbackTransaction, &Error::RollbackTransaction) => true,
418 (&Error::AlreadyInTransaction, &Error::AlreadyInTransaction) => true,
419_ => false,
420 }
421 }
422}
423424#[cfg(test)]
425#[allow(warnings)]
426fn error_impls_send() {
427let err: Error = unimplemented!();
428let x: &dyn Send = &err;
429}
430431/// An unexpected `NULL` was encountered during deserialization
432#[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]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for UnexpectedNullError { }
#[automatically_derived]
impl ::core::clone::Clone for UnexpectedNullError {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for UnexpectedNullError { }Copy)]
433pub struct UnexpectedNullError;
434435impl fmt::Displayfor UnexpectedNullError {
436fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
437f.write_fmt(format_args!("Unexpected null for non-null column"))write!(f, "Unexpected null for non-null column")438 }
439}
440441impl StdErrorfor UnexpectedNullError {}
442443/// Expected more fields then present in the current row while deserializing results
444#[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]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for UnexpectedEndOfRow { }
#[automatically_derived]
impl ::core::clone::Clone for UnexpectedEndOfRow {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for UnexpectedEndOfRow { }Copy)]
445pub struct UnexpectedEndOfRow;
446447impl fmt::Displayfor UnexpectedEndOfRow {
448fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
449f.write_fmt(format_args!("Unexpected end of row"))write!(f, "Unexpected end of row")450 }
451}
452453impl StdErrorfor UnexpectedEndOfRow {}
454455/// Expected when an update has no changes to save.
456///
457/// When using `optional_empty_changeset`, this error is turned into `None`.
458#[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]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for EmptyChangeset { }
#[automatically_derived]
impl ::core::clone::Clone for EmptyChangeset {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for EmptyChangeset { }Copy)]
459pub struct EmptyChangeset;
460461impl fmt::Displayfor EmptyChangeset {
462fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
463f.write_fmt(format_args!("There are no changes to save. This query cannot be built"))write!(
464f,
465"There are no changes to save. This query cannot be built"
466)467 }
468}
469470impl StdErrorfor EmptyChangeset {}
471472/// Expected when you try to execute an empty query
473#[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]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for EmptyQuery { }
#[automatically_derived]
impl ::core::clone::Clone for EmptyQuery {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for EmptyQuery { }Copy)]
474pub struct EmptyQuery;
475476impl fmt::Displayfor EmptyQuery {
477fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
478f.write_fmt(format_args!("Detected an empty query. These are not supported by your database system"))write!(
479f,
480"Detected an empty query. These are not supported by your database system"
481)482 }
483}
484485impl StdErrorfor EmptyQuery {}
486487/// An error occurred while deserializing a field
488#[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)]
489#[non_exhaustive]
490pub struct DeserializeFieldError {
491/// The name of the field that failed to deserialize
492pub field_name: Option<String>,
493/// The error that occurred while deserializing the field
494pub error: Box<dyn StdError + Send + Sync>,
495}
496497impl DeserializeFieldError {
498#[cold]
499pub(crate) fn new<'a, F, DB>(field: F, error: Box<dyn std::error::Error + Send + Sync>) -> Self
500where
501DB: crate::backend::Backend,
502 F: crate::row::Field<'a, DB>,
503 {
504DeserializeFieldError {
505 field_name: field.field_name().map(|s| s.to_string()),
506error,
507 }
508 }
509}
510511impl StdErrorfor DeserializeFieldError {
512fn source(&self) -> Option<&(dyn StdError + 'static)> {
513Some(&*self.error)
514 }
515}
516517impl fmt::Displayfor DeserializeFieldError {
518fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
519if let Some(ref field_name) = self.field_name {
520f.write_fmt(format_args!("Error deserializing field \'{0}\'", field_name))write!(f, "Error deserializing field '{field_name}'")521 } else {
522f.write_str("Error deserializing field")
523 }
524 }
525}