1//! Errors, type aliases, and functions related to working with `Result`.
23use alloc::boxed::Box;
4use alloc::ffi::NulError;
5use alloc::string::String;
6use alloc::string::ToString;
7use core::error::Erroras StdError;
8use core::fmt::{self, Display};
910#[doc(inline)]
11pub use sqlstate::{InvalidSqlState, SqlState, SqlStateClass};
1213#[derive(#[automatically_derived]#[allow(clippy::enum_variant_names)]
impl ::core::fmt::Debug for Error {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::InvalidCString(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"InvalidCString", &__self_0),
Self::DatabaseError(__self_0, __self_1) =>
::core::fmt::Formatter::debug_struct_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_struct_field1_finish(f,
"QueryBuilderError", &__self_0),
Self::DeserializationError(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"DeserializationError", &__self_0),
Self::SerializationError(__self_0) =>
::core::fmt::Formatter::debug_struct_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 commit_error",
__self_0, &__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_struct_field1_finish(f,
"IntegerConversion", &__self_0),
Self::ClosingHandle(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"ClosingHandle", &__self_0),
}
}
}Debug)]
14#[allow(clippy::enum_variant_names)]
15/// Represents all the ways that a query can fail.
16///
17/// This type is not intended to be exhaustively matched, and new variants may
18/// be added in the future without a major version bump.
19#[non_exhaustive]
20pub enum Error {
21/// The query contained a nul byte.
22 ///
23 /// This should never occur in normal usage.
24InvalidCString(NulError),
2526/// The database returned an error.
27 ///
28 /// While Diesel prevents almost all sources of runtime errors at compile
29 /// time, it does not attempt to prevent 100% of them. Typically this error
30 /// will occur from insert or update statements due to a constraint
31 /// violation.
32DatabaseError(
33DatabaseErrorKind,
34Box<dyn DatabaseErrorInformation + Send + Sync>,
35 ),
3637/// No rows were returned by a query expected to return at least one row.
38 ///
39 /// This variant is only returned by [`get_result`] and [`first`]. [`load`]
40 /// does not treat 0 rows as an error. If you would like to allow either 0
41 /// or 1 rows, call [`optional`] on the result.
42 ///
43 /// [`get_result`]: crate::query_dsl::RunQueryDsl::get_result()
44 /// [`first`]: crate::query_dsl::RunQueryDsl::first()
45 /// [`load`]: crate::query_dsl::RunQueryDsl::load()
46 /// [`optional`]: OptionalExtension::optional
47NotFound,
4849/// The query could not be constructed
50 ///
51 /// An example of when this error could occur is if you are attempting to
52 /// construct an update statement with no changes (e.g. all fields on the
53 /// struct are `None`).
54QueryBuilderError(Box<dyn StdError + Send + Sync>),
5556/// An error occurred deserializing the data being sent to the database.
57 ///
58 /// Typically this error means that the stated type of the query is
59 /// incorrect. An example of when this error might occur in normal usage is
60 /// attempting to deserialize an infinite date into chrono.
61DeserializationError(Box<dyn StdError + Send + Sync>),
6263/// An error occurred serializing the data being sent to the database.
64 ///
65 /// An example of when this error would be returned is if you attempted to
66 /// serialize a `chrono::NaiveDate` earlier than the earliest date supported
67 /// by PostgreSQL.
68SerializationError(Box<dyn StdError + Send + Sync>),
6970/// An error occurred when attempting rollback of a transaction subsequently to a failed
71 /// commit attempt.
72 ///
73 /// When a commit attempt fails and Diesel believes that it can attempt a rollback to return
74 /// the connection back in a usable state (out of that transaction), it attempts it then
75 /// returns the original error.
76 ///
77 /// If that fails, you get this.
78RollbackErrorOnCommit {
79/// The error that was encountered when attempting the rollback
80rollback_error: Box<Error>,
81/// The error that was encountered during the failed commit attempt
82commit_error: Box<Error>,
83 },
8485/// Roll back the current transaction.
86 ///
87 /// You can return this variant inside of a transaction when you want to
88 /// roll it back, but have no actual error to return. Diesel will never
89 /// return this variant unless you gave it to us, and it can be safely
90 /// ignored in error handling.
91RollbackTransaction,
9293/// Attempted to perform an operation that cannot be done inside a transaction
94 /// when a transaction was already open.
95AlreadyInTransaction,
9697/// Attempted to perform an operation that can only be done inside a transaction
98 /// when no transaction was open
99NotInTransaction,
100101/// Transaction manager broken, likely due to a broken connection. No other operations are possible.
102BrokenTransactionManager,
103104/// Internal integer conversion failed
105IntegerConversion(core::num::TryFromIntError),
106107/// Closing a handle failed
108ClosingHandle(&'static str),
109}
110111#[derive(#[automatically_derived]impl ::core::fmt::Debug for DatabaseErrorKind {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_c_like_enum_write_str(f,
"UniqueViolation ForeignKeyViolation UnableToSendCommand SerializationFailure ReadOnlyTransaction RestrictViolation NotNullViolation CheckViolation ExclusionViolation ClosedConnection Unknown",
match self {
DatabaseErrorKind::UniqueViolation => 0usize,
DatabaseErrorKind::ForeignKeyViolation => 16usize,
DatabaseErrorKind::UnableToSendCommand => 36usize,
DatabaseErrorKind::SerializationFailure => 56usize,
DatabaseErrorKind::ReadOnlyTransaction => 77usize,
DatabaseErrorKind::RestrictViolation => 97usize,
DatabaseErrorKind::NotNullViolation => 115usize,
DatabaseErrorKind::CheckViolation => 132usize,
DatabaseErrorKind::ExclusionViolation => 147usize,
DatabaseErrorKind::ClosedConnection => 166usize,
DatabaseErrorKind::Unknown => 183usize,
})
}
}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]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for DatabaseErrorKind { }Copy)]
112/// The kind of database error that occurred.
113///
114/// This is not meant to exhaustively cover all possible errors, but is used to
115/// identify errors which are commonly recovered from programmatically. This enum
116/// is not intended to be exhaustively matched, and new variants may be added in
117/// the future without a major version bump.
118#[non_exhaustive]
119pub enum DatabaseErrorKind {
120/// A unique constraint was violated.
121UniqueViolation = 0,
122123/// A foreign key constraint was violated.
124ForeignKeyViolation = 1,
125126/// The query could not be sent to the database due to a protocol violation.
127 ///
128 /// An example of a case where this would occur is if you attempted to send
129 /// a query with more than 65000 bind parameters using PostgreSQL.
130UnableToSendCommand = 2,
131132/// A serializable transaction failed to commit due to a read/write
133 /// dependency on a concurrent transaction.
134 ///
135 /// Corresponds to SQLSTATE code 40001
136 ///
137 /// This error is only detected for PostgreSQL, as we do not yet support
138 /// transaction isolation levels for other backends.
139SerializationFailure = 3,
140141/// The command could not be completed because the transaction was read
142 /// only.
143 ///
144 /// This error will also be returned for `SELECT` statements which attempted
145 /// to lock the rows.
146ReadOnlyTransaction = 4,
147148/// A restrict constraint was violated.
149RestrictViolation = 9,
150151/// A not null constraint was violated.
152NotNullViolation = 5,
153154/// A check constraint was violated.
155CheckViolation = 6,
156157/// An exclusion constraint was violated.
158ExclusionViolation = 10,
159160/// The connection to the server was unexpectedly closed.
161 ///
162 /// This error is only detected for PostgreSQL and is emitted on a best-effort basis
163 /// and may be missed.
164ClosedConnection = 7,
165166#[doc(hidden)]
167Unknown = 8, // Match against _ instead, more variants may be added in the future
168}
169170/// Information about an error that was returned by the database.
171pub trait DatabaseErrorInformation {
172/// The primary human-readable error message. Typically one line.
173fn message(&self) -> &str;
174175/// An optional secondary error message providing more details about the
176 /// problem, if it was provided by the database. Might span multiple lines.
177fn details(&self) -> Option<&str>;
178179/// An optional suggestion of what to do about the problem, if one was
180 /// provided by the database.
181fn hint(&self) -> Option<&str>;
182183/// The name of the table the error was associated with, if the error was
184 /// associated with a specific table and the backend supports retrieving
185 /// that information.
186 ///
187 /// Currently this method will return `None` for all backends other than
188 /// PostgreSQL.
189fn table_name(&self) -> Option<&str>;
190191/// The name of the column the error was associated with, if the error was
192 /// associated with a specific column and the backend supports retrieving
193 /// that information.
194 ///
195 /// Currently this method will return `None` for all backends other than
196 /// PostgreSQL.
197fn column_name(&self) -> Option<&str>;
198199/// The constraint that was violated if this error is a constraint violation
200 /// and the backend supports retrieving that information.
201 ///
202 /// Currently this method will return `None` for all backends other than
203 /// PostgreSQL.
204fn constraint_name(&self) -> Option<&str>;
205206/// An optional integer indicating an error cursor position as an index into
207 /// the original statement string.
208fn statement_position(&self) -> Option<i32>;
209210/// The [`SqlState`] of the error, if the connection reports one.
211 ///
212 /// Which errors carry a code is documented by each connection.
213fn sqlstate(&self) -> Option<SqlState> {
214None215 }
216}
217218impl fmt::Debugfor dyn DatabaseErrorInformation + Send + Sync {
219fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
220 fmt::Debug::fmt(&self.message(), f)
221 }
222}
223224impl DatabaseErrorInformationfor String {
225fn message(&self) -> &str {
226self227 }
228fn details(&self) -> Option<&str> {
229None230 }
231fn hint(&self) -> Option<&str> {
232None233 }
234fn table_name(&self) -> Option<&str> {
235None236 }
237fn column_name(&self) -> Option<&str> {
238None239 }
240fn constraint_name(&self) -> Option<&str> {
241None242 }
243fn statement_position(&self) -> Option<i32> {
244None245 }
246}
247248impl DatabaseErrorInformationfor core::convert::Infallible {
249fn message(&self) -> &str {
250match *self {}
251 }
252253fn details(&self) -> Option<&str> {
254match *self {}
255 }
256257fn hint(&self) -> Option<&str> {
258match *self {}
259 }
260261fn table_name(&self) -> Option<&str> {
262match *self {}
263 }
264265fn column_name(&self) -> Option<&str> {
266match *self {}
267 }
268269fn constraint_name(&self) -> Option<&str> {
270match *self {}
271 }
272273fn statement_position(&self) -> Option<i32> {
274match *self {}
275 }
276}
277278/// Errors which can occur during [`Connection::establish`]
279///
280/// [`Connection::establish`]: crate::connection::Connection::establish
281#[derive(#[automatically_derived]impl ::core::fmt::Debug for ConnectionError {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::InvalidCString(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"InvalidCString", &__self_0),
Self::BadConnection(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"BadConnection", &__self_0),
Self::InvalidConnectionUrl(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"InvalidConnectionUrl", &__self_0),
Self::CouldntSetupConfiguration(__self_0) =>
::core::fmt::Formatter::debug_struct_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)]
282#[non_exhaustive]
283pub enum ConnectionError {
284/// The connection URL contained a `NUL` byte.
285InvalidCString(NulError),
286/// The database returned an error.
287BadConnection(String),
288/// The connection URL could not be parsed.
289InvalidConnectionUrl(String),
290/// Diesel could not configure the database connection.
291 ///
292 /// Diesel may try to automatically set session specific configuration
293 /// values, such as UTF8 encoding, or enabling the `||` operator on MySQL.
294 /// This variant is returned if an error occurred executing the query to set
295 /// those options. Diesel will never affect global configuration.
296CouldntSetupConfiguration(Error),
297}
298299/// A specialized result type for queries.
300///
301/// This type is exported by `diesel::prelude`, and is generally used by any
302/// code which is interacting with Diesel. This type exists to avoid writing out
303/// `diesel::result::Error`, and is otherwise a direct mapping to `Result`.
304pub type QueryResult<T> = Result<T, Error>;
305306/// A specialized result type for establishing connections.
307///
308/// This type exists to avoid writing out `diesel::result::ConnectionError`, and
309/// is otherwise a direct mapping to `Result`.
310pub type ConnectionResult<T> = Result<T, ConnectionError>;
311312/// See the [method documentation](OptionalExtension::optional).
313pub trait OptionalExtension<T> {
314/// Converts a `QueryResult<T>` into a `QueryResult<Option<T>>`.
315 ///
316 /// By default, Diesel treats 0 rows being returned from a query that is expected to return 1
317 /// row as an error (e.g. the return value of [`get_result`] or [`first`]). This method will
318 /// handle that error, and give you back an `Option<T>` instead.
319 ///
320 /// [`get_result`]: crate::query_dsl::RunQueryDsl::get_result()
321 /// [`first`]: crate::query_dsl::RunQueryDsl::first()
322 ///
323 /// # Example
324 ///
325 /// ```rust
326 /// use diesel::{NotFound, OptionalExtension, QueryResult};
327 ///
328 /// let result: QueryResult<i32> = Ok(1);
329 /// assert_eq!(Ok(Some(1)), result.optional());
330 ///
331 /// let result: QueryResult<i32> = Err(NotFound);
332 /// assert_eq!(Ok(None), result.optional());
333 /// ```
334fn optional(self) -> Result<Option<T>, Error>;
335}
336337impl<T> OptionalExtension<T> for QueryResult<T> {
338fn optional(self) -> Result<Option<T>, Error> {
339match self {
340Ok(value) => Ok(Some(value)),
341Err(Error::NotFound) => Ok(None),
342Err(e) => Err(e),
343 }
344 }
345}
346347/// See the [method documentation](OptionalEmptyChangesetExtension::optional_empty_changeset).
348pub trait OptionalEmptyChangesetExtension<T> {
349/// By default, Diesel treats an empty update as a `QueryBuilderError`. This method will
350 /// convert that error into `None`.
351 ///
352 /// # Example
353 ///
354 /// ```rust
355 /// use diesel::{
356 /// result::EmptyChangeset, result::Error::QueryBuilderError, OptionalEmptyChangesetExtension,
357 /// QueryResult,
358 /// };
359 /// let result: QueryResult<i32> = Err(QueryBuilderError(Box::new(EmptyChangeset)));
360 /// assert_eq!(Ok(None), result.optional_empty_changeset());
361 /// ```
362fn optional_empty_changeset(self) -> Result<Option<T>, Error>;
363}
364365impl<T> OptionalEmptyChangesetExtension<T> for QueryResult<T> {
366fn optional_empty_changeset(self) -> Result<Option<T>, Error> {
367match self {
368Ok(value) => Ok(Some(value)),
369Err(Error::QueryBuilderError(e)) if e.is::<EmptyChangeset>() => Ok(None),
370Err(e) => Err(e),
371 }
372 }
373}
374375impl From<NulError> for ConnectionError {
376fn from(e: NulError) -> Self {
377 ConnectionError::InvalidCString(e)
378 }
379}
380381impl From<NulError> for Error {
382fn from(e: NulError) -> Self {
383 Error::InvalidCString(e)
384 }
385}
386387impl Displayfor Error {
388fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
389match *self {
390 Error::InvalidCString(ref nul_err) => f.write_fmt(format_args!("{0}", nul_err))write!(f, "{nul_err}"),
391 Error::DatabaseError(_, ref e) => f.write_fmt(format_args!("{0}", e.message()))write!(f, "{}", e.message()),
392 Error::NotFound => f.write_str("Record not found"),
393 Error::QueryBuilderError(ref e) => e.fmt(f),
394 Error::DeserializationError(ref e) => e.fmt(f),
395 Error::SerializationError(ref e) => e.fmt(f),
396 Error::RollbackErrorOnCommit {
397ref rollback_error,
398ref commit_error,
399 } => {
400f.write_fmt(format_args!("Transaction rollback failed: {0} (rollback attempted because of failure to commit: {1})",
rollback_error, commit_error))write!(
401 f,
402"Transaction rollback failed: {rollback_error} \
403 (rollback attempted because of failure to commit: {commit_error})",
404 )?;
405Ok(())
406 }
407 Error::RollbackTransaction => {
408f.write_fmt(format_args!("You have asked diesel to rollback the transaction"))write!(f, "You have asked diesel to rollback the transaction")409 }
410 Error::BrokenTransactionManager => f.write_fmt(format_args!("The transaction manager is broken"))write!(f, "The transaction manager is broken"),
411 Error::AlreadyInTransaction => f.write_fmt(format_args!("Cannot perform this operation while a transaction is open"))write!(
412f,
413"Cannot perform this operation while a transaction is open",
414 ),
415 Error::NotInTransaction => {
416f.write_fmt(format_args!("Cannot perform this operation outside of a transaction"))write!(f, "Cannot perform this operation outside of a transaction",)417 }
418 Error::IntegerConversion(_) => f.write_str("Internal integer conversion failed"),
419 Error::ClosingHandle(message) => {
420f.write_fmt(format_args!("Error closing SQLite blob: {0}", message))write!(f, "Error closing SQLite blob: {message}")421 }
422 }
423 }
424}
425426impl StdErrorfor Error {
427fn source(&self) -> Option<&(dyn StdError + 'static)> {
428match *self {
429 Error::InvalidCString(ref e) => e.source(),
430 Error::QueryBuilderError(ref e) => e.source(),
431 Error::DeserializationError(ref e) => e.source(),
432 Error::SerializationError(ref e) => e.source(),
433 Error::IntegerConversion(ref e) => Some(e),
434_ => None,
435 }
436 }
437}
438439impl Displayfor ConnectionError {
440fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
441match *self {
442 ConnectionError::InvalidCString(ref nul_err) => nul_err.fmt(f),
443 ConnectionError::BadConnection(ref s) => f.write_fmt(format_args!("{0}", s))write!(f, "{s}"),
444 ConnectionError::InvalidConnectionUrl(ref s) => f.write_fmt(format_args!("{0}", s))write!(f, "{s}"),
445 ConnectionError::CouldntSetupConfiguration(ref e) => e.fmt(f),
446 }
447 }
448}
449450impl StdErrorfor ConnectionError {
451fn source(&self) -> Option<&(dyn StdError + 'static)> {
452match *self {
453 ConnectionError::InvalidCString(ref e) => e.source(),
454 ConnectionError::CouldntSetupConfiguration(ref e) => e.source(),
455_ => None,
456 }
457 }
458}
459460impl PartialEqfor Error {
461fn eq(&self, other: &Error) -> bool {
462match (self, other) {
463 (Error::InvalidCString(a), Error::InvalidCString(b)) => a == b,
464 (Error::DatabaseError(_, a), Error::DatabaseError(_, b)) => a.message() == b.message(),
465 (&Error::NotFound, &Error::NotFound) => true,
466 (&Error::RollbackTransaction, &Error::RollbackTransaction) => true,
467 (&Error::AlreadyInTransaction, &Error::AlreadyInTransaction) => true,
468_ => false,
469 }
470 }
471}
472473#[cfg(test)]
474#[allow(warnings)]
475fn error_impls_send() {
476let err: Error = unimplemented!();
477let x: &dyn Send = &err;
478}
479480#[cfg(test)]
481#[allow(warnings)]
482fn infallible_impls_database_error_information() {
483let err: core::convert::Infallible = unimplemented!();
484let x: &dyn DatabaseErrorInformation = &err;
485}
486487/// An unexpected `NULL` was encountered during deserialization
488#[derive(#[automatically_derived]impl ::core::fmt::Debug for UnexpectedNullError {
#[inline]
#[rustc_trivial_field_reads]
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]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for UnexpectedNullError { }Copy)]
489pub struct UnexpectedNullError;
490491impl fmt::Displayfor UnexpectedNullError {
492fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
493f.write_fmt(format_args!("Unexpected null for non-null column"))write!(f, "Unexpected null for non-null column")494 }
495}
496497impl StdErrorfor UnexpectedNullError {}
498499/// Expected more fields then present in the current row while deserializing results
500#[derive(#[automatically_derived]impl ::core::fmt::Debug for UnexpectedEndOfRow {
#[inline]
#[rustc_trivial_field_reads]
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]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for UnexpectedEndOfRow { }Copy)]
501pub struct UnexpectedEndOfRow;
502503impl fmt::Displayfor UnexpectedEndOfRow {
504fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
505f.write_fmt(format_args!("Unexpected end of row"))write!(f, "Unexpected end of row")506 }
507}
508509impl StdErrorfor UnexpectedEndOfRow {}
510511/// Expected when an update has no changes to save.
512///
513/// When using `optional_empty_changeset`, this error is turned into `None`.
514#[derive(#[automatically_derived]impl ::core::fmt::Debug for EmptyChangeset {
#[inline]
#[rustc_trivial_field_reads]
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]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for EmptyChangeset { }Copy)]
515pub struct EmptyChangeset;
516517impl fmt::Displayfor EmptyChangeset {
518fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
519f.write_fmt(format_args!("There are no changes to save. This query cannot be built"))write!(
520f,
521"There are no changes to save. This query cannot be built"
522)523 }
524}
525526impl StdErrorfor EmptyChangeset {}
527528/// Expected when you try to execute an empty query
529#[derive(#[automatically_derived]impl ::core::fmt::Debug for EmptyQuery {
#[inline]
#[rustc_trivial_field_reads]
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]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for EmptyQuery { }Copy)]
530pub struct EmptyQuery;
531532impl fmt::Displayfor EmptyQuery {
533fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
534f.write_fmt(format_args!("Detected an empty query. These are not supported by your database system"))write!(
535f,
536"Detected an empty query. These are not supported by your database system"
537)538 }
539}
540541impl StdErrorfor EmptyQuery {}
542543/// An error occurred while deserializing a field
544#[derive(#[automatically_derived]impl ::core::fmt::Debug for DeserializeFieldError {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"DeserializeFieldError field_name error", &self.field_name,
&&self.error)
}
}Debug)]
545#[non_exhaustive]
546pub struct DeserializeFieldError {
547/// The name of the field that failed to deserialize
548pub field_name: Option<String>,
549/// The error that occurred while deserializing the field
550pub error: Box<dyn StdError + Send + Sync>,
551}
552553impl DeserializeFieldError {
554#[cold]
555pub(crate) fn new<'a, F, DB>(field: F, error: Box<dyn core::error::Error + Send + Sync>) -> Self
556where
557DB: crate::backend::Backend,
558 F: crate::row::Field<'a, DB>,
559 {
560DeserializeFieldError {
561 field_name: field.field_name().map(|s| s.to_string()),
562error,
563 }
564 }
565}
566567impl StdErrorfor DeserializeFieldError {
568fn source(&self) -> Option<&(dyn StdError + 'static)> {
569Some(&*self.error)
570 }
571}
572573impl fmt::Displayfor DeserializeFieldError {
574fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
575if let Some(ref field_name) = self.field_name {
576f.write_fmt(format_args!("Error deserializing field \'{0}\'", field_name))write!(f, "Error deserializing field '{field_name}'")577 } else {
578f.write_str("Error deserializing field")
579 }
580 }
581}