Debian Codegraph @

src/error.rs

raw symbols SCIP
1 //! Types for working with errors produced by SQLx.
2
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/::type_namerust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/type_name().;
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#;
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# as StdErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#;
6 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#;
7 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/;
8
9 use craterust-analyzer cargo sqlx-core 0.8.3 crate/::databaserust-analyzer cargo sqlx-core 0.8.3 database/::Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#;
10
11 use craterust-analyzer cargo sqlx-core 0.8.3 crate/::type_inforust-analyzer cargo sqlx-core 0.8.3 type_info/::TypeInforust-analyzer cargo sqlx-core 0.8.3 type_info/TypeInfo#;
12 use craterust-analyzer cargo sqlx-core 0.8.3 crate/::typesrust-analyzer cargo sqlx-core 0.8.3 types/::Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#;
13
14 /// A specialized `Result` type for SQLx.
15 pub type Resultrust-analyzer cargo sqlx-core 0.8.3 error/Result#<T, E = Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> = ::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>;
16
17 // Convenience type alias for usage within SQLx.
18 // Do not make this type public.
19 pub type BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError# = Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn StdErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + 'static + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#>;
20
21 /// An unexpected `NULL` was encountered during decoding.
22 ///
23 /// Returned from [`Row::get`](crate::row::Row::get) if the value from the database is `NULL`,
24 /// and you are not decoding into an `Option`.
25 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(thiserrorrust-analyzer cargo thiserror 2.0.20 crate/::Errorrust-analyzer cargo thiserror-impl 2.0.20 Error:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
26 #[error("unexpected null; try decoding as an `Option`")]
27 pub struct UnexpectedNullErrorrust-analyzer cargo sqlx-core 0.8.3 error/UnexpectedNullError#;
28
29 /// Represents all the ways a method can fail within SQLx.
30 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, thiserrorrust-analyzer cargo thiserror 2.0.20 crate/::Errorrust-analyzer cargo thiserror-impl 2.0.20 Error:)]
31 #[non_exhaustive]
32 pub enum Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error# {
33 /// Error occurred while parsing a connection string.
34 #[errorrust-analyzer cargo thiserror-impl 2.0.20 error:("error with configuration: {0}")]
35 Configurationrust-analyzer cargo sqlx-core 0.8.3 error/Error#Configuration#(#[source] BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#),
36
37 /// Error returned from the database.
38 #[errorrust-analyzer cargo thiserror-impl 2.0.20 error:("error returned from database: {0}")]
39 Databaserust-analyzer cargo sqlx-core 0.8.3 error/Error#Database#(#[source] Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn DatabaseErrorrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#>),
40
41 /// Error communicating with the database backend.
42 #[errorrust-analyzer cargo thiserror-impl 2.0.20 error:("error communicating with database: {0}")]
43 Iorust-analyzer cargo sqlx-core 0.8.3 error/Error#Io#(#[from] iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#),
44
45 /// Error occurred while attempting to establish a TLS connection.
46 #[errorrust-analyzer cargo thiserror-impl 2.0.20 error:("error occurred while attempting to establish a TLS connection: {0}")]
47 Tlsrust-analyzer cargo sqlx-core 0.8.3 error/Error#Tls#(#[source] BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#),
48
49 /// Unexpected or invalid data encountered while communicating with the database.
50 ///
51 /// This should indicate there is a programming error in a SQLx driver or there
52 /// is something corrupted with the connection to the database itself.
53 #[errorrust-analyzer cargo thiserror-impl 2.0.20 error:("encountered unexpected or invalid data: {0}")]
54 Protocolrust-analyzer cargo sqlx-core 0.8.3 error/Error#Protocol#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#),
55
56 /// No rows returned by a query that expected to return at least one row.
57 #[errorrust-analyzer cargo thiserror-impl 2.0.20 error:("no rows returned by a query that expected to return at least one row")]
58 RowNotFoundrust-analyzer cargo sqlx-core 0.8.3 error/Error#RowNotFound#,
59
60 /// Type in query doesn't exist. Likely due to typo or missing user type.
61 #[errorrust-analyzer cargo thiserror-impl 2.0.20 error:("type named {type_name} not found")]
62 TypeNotFoundrust-analyzer cargo sqlx-core 0.8.3 error/Error#TypeNotFound# { type_namerust-analyzer cargo sqlx-core 0.8.3 error/Error#TypeNotFound#type_name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# },
63
64 /// Column index was out of bounds.
65 #[errorrust-analyzer cargo thiserror-impl 2.0.20 error:("column index out of bounds: the len is {len}, but the index is {index}")]
66 ColumnIndexOutOfBoundsrust-analyzer cargo sqlx-core 0.8.3 error/Error#ColumnIndexOutOfBounds# { indexrust-analyzer cargo sqlx-core 0.8.3 error/Error#ColumnIndexOutOfBounds#index.: usize, lenrust-analyzer cargo sqlx-core 0.8.3 error/Error#ColumnIndexOutOfBounds#len.: usize },
67
68 /// No column found for the given name.
69 #[errorrust-analyzer cargo thiserror-impl 2.0.20 error:("no column found for name: {0}")]
70 ColumnNotFoundrust-analyzer cargo sqlx-core 0.8.3 error/Error#ColumnNotFound#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#),
71
72 /// Error occurred while decoding a value from a specific column.
73 #[errorrust-analyzer cargo thiserror-impl 2.0.20 error:("error occurred while decoding column {index}: {source}")]
74 ColumnDecoderust-analyzer cargo sqlx-core 0.8.3 error/Error#ColumnDecode# {
75 indexrust-analyzer cargo sqlx-core 0.8.3 error/Error#ColumnDecode#index.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
76
77 #[source]
78 sourcerust-analyzer cargo sqlx-core 0.8.3 error/Error#ColumnDecode#source.: BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#,
79 },
80
81 /// Error occured while encoding a value.
82 #[errorrust-analyzer cargo thiserror-impl 2.0.20 error:("error occured while encoding a value: {0}")]
83 Encoderust-analyzer cargo sqlx-core 0.8.3 error/Error#Encode#(#[source] BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#),
84
85 /// Error occurred while decoding a value.
86 #[errorrust-analyzer cargo thiserror-impl 2.0.20 error:("error occurred while decoding: {0}")]
87 Decoderust-analyzer cargo sqlx-core 0.8.3 error/Error#Decode#(#[source] BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#),
88
89 /// Error occurred within the `Any` driver mapping to/from the native driver.
90 #[errorrust-analyzer cargo thiserror-impl 2.0.20 error:("error in Any driver mapping: {0}")]
91 AnyDriverErrorrust-analyzer cargo sqlx-core 0.8.3 error/Error#AnyDriverError#(#[source] BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#),
92
93 /// A [`Pool::acquire`] timed out due to connections not becoming available or
94 /// because another task encountered too many errors while trying to open a new connection.
95 ///
96 /// [`Pool::acquire`]: crate::pool::Pool::acquire
97 #[errorrust-analyzer cargo thiserror-impl 2.0.20 error:("pool timed out while waiting for an open connection")]
98 PoolTimedOutrust-analyzer cargo sqlx-core 0.8.3 error/Error#PoolTimedOut#,
99
100 /// [`Pool::close`] was called while we were waiting in [`Pool::acquire`].
101 ///
102 /// [`Pool::acquire`]: crate::pool::Pool::acquire
103 /// [`Pool::close`]: crate::pool::Pool::close
104 #[errorrust-analyzer cargo thiserror-impl 2.0.20 error:("attempted to acquire a connection on a closed pool")]
105 PoolClosedrust-analyzer cargo sqlx-core 0.8.3 error/Error#PoolClosed#,
106
107 /// A background worker has crashed.
108 #[errorrust-analyzer cargo thiserror-impl 2.0.20 error:("attempted to communicate with a crashed background worker")]
109 WorkerCrashedrust-analyzer cargo sqlx-core 0.8.3 error/Error#WorkerCrashed#,
110
111 #[cfg(feature = "migrate")]
112 #[errorrust-analyzer cargo thiserror-impl 2.0.20 error:("{0}")]
113 Migraterust-analyzer cargo sqlx-core 0.8.3 error/Error#Migrate#(#[source] Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<craterust-analyzer cargo sqlx-core 0.8.3 crate/::migraterust-analyzer cargo sqlx-core 0.8.3 migrate/::MigrateErrorrust-analyzer cargo sqlx-core 0.8.3 migrate/error/MigrateError#>),
114 }
115
116 impl StdErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn DatabaseErrorrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#> {}
117
118 impl Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error# {
119 pub fn into_database_errorrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error]into_database_error().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn DatabaseErrorrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError# + 'static>> {
120 match self {
121 Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::Databaserust-analyzer cargo sqlx-core 0.8.3 error/Error#Database#(err) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(err),
122 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
123 }
124 }
125
126 pub fn as_database_errorrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error]as_database_error().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&(dyn DatabaseErrorrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError# + 'static)> {
127 match self {
128 Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::Databaserust-analyzer cargo sqlx-core 0.8.3 error/Error#Database#(err) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().err),
129 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
130 }
131 }
132
133 #[doc(hidden)]
134 #[inline]
135 pub fn protocolrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error]protocol().(err: impl Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#) -> Selfrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error] {
136 Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::Protocolrust-analyzer cargo sqlx-core 0.8.3 error/Error#Protocol#(err.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
137 }
138
139 #[doc(hidden)]
140 #[inline]
141 pub fn configrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error]config().(err: impl StdErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static) -> Selfrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error] {
142 Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::Configurationrust-analyzer cargo sqlx-core 0.8.3 error/Error#Configuration#(err.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
143 }
144
145 pub(craterust-analyzer cargo sqlx-core 0.8.3 crate/) fn tlsrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error]tls().(err: impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn StdErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static>>) -> Selfrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error] {
146 Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::Tlsrust-analyzer cargo sqlx-core 0.8.3 error/Error#Tls#(err.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().())
147 }
148
149 #[doc(hidden)]
150 #[inline]
151 pub fn decoderust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error]decode().(err: impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn StdErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static>>) -> Selfrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error] {
152 Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::Decoderust-analyzer cargo sqlx-core 0.8.3 error/Error#Decode#(err.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().())
153 }
154 }
155
156 pub fn mismatched_typesrust-analyzer cargo sqlx-core 0.8.3 error/mismatched_types().<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#, T: Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<DB>>(ty: &DB::TypeInforust-analyzer cargo sqlx-core 0.8.3 database/Database#TypeInfo#) -> BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError# {
157 // TODO: `#name` only produces `TINYINT` but perhaps we want to show `TINYINT(1)`
158 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
159 "mismatched types; Rust type `{}` (as SQL type `{}`) is not compatible with SQL type `{}`",
160 type_namerust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/type_name().::<T>(),
161 T::type_inforust-analyzer cargo sqlx-core 0.8.3 types/Type#type_info().().namerust-analyzer cargo sqlx-core 0.8.3 type_info/TypeInfo#name().(),
162 ty.namerust-analyzer cargo sqlx-core 0.8.3 type_info/TypeInfo#name().()
163 )
164 .intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
165 }
166
167 /// The error kind.
168 ///
169 /// This enum is to be used to identify frequent errors that can be handled by the program.
170 /// Although it currently only supports constraint violations, the type may grow in the future.
171 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
172 #[non_exhaustive]
173 pub enum ErrorKindrust-analyzer cargo sqlx-core 0.8.3 error/ErrorKind# {
174 /// Unique/primary key constraint violation.
175 UniqueViolationrust-analyzer cargo sqlx-core 0.8.3 error/ErrorKind#UniqueViolation#,
176 /// Foreign key constraint violation.
177 ForeignKeyViolationrust-analyzer cargo sqlx-core 0.8.3 error/ErrorKind#ForeignKeyViolation#,
178 /// Not-null constraint violation.
179 NotNullViolationrust-analyzer cargo sqlx-core 0.8.3 error/ErrorKind#NotNullViolation#,
180 /// Check constraint violation.
181 CheckViolationrust-analyzer cargo sqlx-core 0.8.3 error/ErrorKind#CheckViolation#,
182 /// An unmapped error.
183 Otherrust-analyzer cargo sqlx-core 0.8.3 error/ErrorKind#Other#,
184 }
185
186 /// An error that was returned from the database.
187 pub trait DatabaseErrorrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#: 'static + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + StdErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# {
188 /// The primary, human-readable error message.
189 fn messagerust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#message().(&self) -> &str;
190
191 /// The (SQLSTATE) code for the error.
192 fn coderust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#code().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, str>> {
193 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
194 }
195
196 #[doc(hidden)]
197 fn as_errorrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#as_error().(&self) -> &(dyn StdErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static);
198
199 #[doc(hidden)]
200 fn as_error_mutrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#as_error_mut().(&mut self) -> &mut (dyn StdErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static);
201
202 #[doc(hidden)]
203 fn into_errorrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#into_error().(self: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Self>) -> Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn StdErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static>;
204
205 #[doc(hidden)]
206 fn is_transient_in_connect_phaserust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#is_transient_in_connect_phase().(&self) -> bool {
207 false
208 }
209
210 /// Returns the name of the constraint that triggered the error, if applicable.
211 /// If the error was caused by a conflict of a unique index, this will be the index name.
212 ///
213 /// ### Note
214 /// Currently only populated by the Postgres driver.
215 fn constraintrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#constraint().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str> {
216 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
217 }
218
219 /// Returns the name of the table that was affected by the error, if applicable.
220 ///
221 /// ### Note
222 /// Currently only populated by the Postgres driver.
223 fn tablerust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#table().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str> {
224 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
225 }
226
227 /// Returns the kind of the error, if supported.
228 ///
229 /// ### Note
230 /// Not all back-ends behave the same when reporting the error code.
231 fn kindrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#kind().(&self) -> ErrorKindrust-analyzer cargo sqlx-core 0.8.3 error/ErrorKind#;
232
233 /// Returns whether the error kind is a violation of a unique/primary key constraint.
234 fn is_unique_violationrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#is_unique_violation().(&self) -> bool {
235 matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self.kindrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#kind().(), ErrorKindrust-analyzer cargo sqlx-core 0.8.3 error/ErrorKind#::UniqueViolationrust-analyzer cargo sqlx-core 0.8.3 error/ErrorKind#UniqueViolation#)
236 }
237
238 /// Returns whether the error kind is a violation of a foreign key.
239 fn is_foreign_key_violationrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#is_foreign_key_violation().(&self) -> bool {
240 matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self.kindrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#kind().(), ErrorKindrust-analyzer cargo sqlx-core 0.8.3 error/ErrorKind#::ForeignKeyViolationrust-analyzer cargo sqlx-core 0.8.3 error/ErrorKind#ForeignKeyViolation#)
241 }
242
243 /// Returns whether the error kind is a violation of a check.
244 fn is_check_violationrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#is_check_violation().(&self) -> bool {
245 matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self.kindrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#kind().(), ErrorKindrust-analyzer cargo sqlx-core 0.8.3 error/ErrorKind#::CheckViolationrust-analyzer cargo sqlx-core 0.8.3 error/ErrorKind#CheckViolation#)
246 }
247 }
248
249 impl dyn DatabaseErrorrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError# {
250 /// Downcast a reference to this generic database error to a specific
251 /// database error type.
252 ///
253 /// # Panics
254 ///
255 /// Panics if the database error type is not `E`. This is a deliberate contrast from
256 /// `Error::downcast_ref` which returns `Option<&E>`. In normal usage, you should know the
257 /// specific error type. In other cases, use `try_downcast_ref`.
258 pub fn downcast_refrust-analyzer cargo sqlx-core 0.8.3 error/impl#[`dyn DatabaseError + 'static`]downcast_ref().<E: DatabaseErrorrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#>(&self) -> &E {
259 self.try_downcast_refrust-analyzer cargo sqlx-core 0.8.3 error/impl#[`dyn DatabaseError + 'static`]try_downcast_ref().().unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| {
260 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("downcast to wrong DatabaseError type; original error: {self}")
261 })
262 }
263
264 /// Downcast this generic database error to a specific database error type.
265 ///
266 /// # Panics
267 ///
268 /// Panics if the database error type is not `E`. This is a deliberate contrast from
269 /// `Error::downcast` which returns `Option<E>`. In normal usage, you should know the
270 /// specific error type. In other cases, use `try_downcast`.
271 pub fn downcastrust-analyzer cargo sqlx-core 0.8.3 error/impl#[`dyn DatabaseError + 'static`]downcast().<E: DatabaseErrorrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#>(self: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Selfrust-analyzer cargo sqlx-core 0.8.3 error/impl#[`dyn DatabaseError + 'static`]>) -> Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<E> {
272 self.try_downcastrust-analyzer cargo sqlx-core 0.8.3 error/impl#[`dyn DatabaseError + 'static`]try_downcast().()
273 .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(|e| panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("downcast to wrong DatabaseError type; original error: {e}"))
274 }
275
276 /// Downcast a reference to this generic database error to a specific
277 /// database error type.
278 #[inline]
279 pub fn try_downcast_refrust-analyzer cargo sqlx-core 0.8.3 error/impl#[`dyn DatabaseError + 'static`]try_downcast_ref().<E: DatabaseErrorrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#>(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&E> {
280 self.as_errorrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#as_error().().downcast_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/impl#[`dyn Error + Send + Sync + 'static`]downcast_ref().()
281 }
282
283 /// Downcast this generic database error to a specific database error type.
284 #[inline]
285 pub fn try_downcastrust-analyzer cargo sqlx-core 0.8.3 error/impl#[`dyn DatabaseError + 'static`]try_downcast().<E: DatabaseErrorrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#>(self: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Selfrust-analyzer cargo sqlx-core 0.8.3 error/impl#[`dyn DatabaseError + 'static`]>) -> Resultrust-analyzer cargo sqlx-core 0.8.3 error/Result#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<E>, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Selfrust-analyzer cargo sqlx-core 0.8.3 error/impl#[`dyn DatabaseError + 'static`]>> {
286 if self.as_errorrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#as_error().().isrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/impl#[`dyn Error + Send + Sync + 'static`]is().::<E>() {
287 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.into_errorrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#into_error().().downcastrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/convert/impl#[`dyn Error + Send + Sync + 'static`]downcast().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().())
288 } else {
289 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(self)
290 }
291 }
292 }
293
294 impl<E> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<E> for Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#
295 where
296 E: DatabaseErrorrust-analyzer cargo sqlx-core 0.8.3 error/DatabaseError#,
297 {
298 #[inline]
299 fn fromrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error][`From<E>`]from().(error: E) -> Selfrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error][`From<E>`] {
300 Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::Databaserust-analyzer cargo sqlx-core 0.8.3 error/Error#Database#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(error))
301 }
302 }
303
304 #[cfg(feature = "migrate")]
305 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<craterust-analyzer cargo sqlx-core 0.8.3 crate/::migraterust-analyzer cargo sqlx-core 0.8.3 migrate/::MigrateErrorrust-analyzer cargo sqlx-core 0.8.3 migrate/error/MigrateError#> for Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error# {
306 #[inline]
307 fn fromrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error][`From<crate::migrate::MigrateError>`]from().(error: craterust-analyzer cargo sqlx-core 0.8.3 crate/::migraterust-analyzer cargo sqlx-core 0.8.3 migrate/::MigrateErrorrust-analyzer cargo sqlx-core 0.8.3 migrate/error/MigrateError#) -> Selfrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error][`From<crate::migrate::MigrateError>`] {
308 Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::Migraterust-analyzer cargo sqlx-core 0.8.3 error/Error#Migrate#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(error))
309 }
310 }
311
312 /// Format an error message as a `Protocol` error
313 #[macro_export]
314 macro_rules! err_protocolrust-analyzer cargo sqlx-core 0.8.3 error/err_protocol! {
315 ($($fmt_args:tt)*) => {
316 $crate::error::Error::Protocol(
317 format!(
318 "{} ({}:{})",
319 // Note: the format string needs to be unmodified (e.g. by `concat!()`)
320 // for implicit formatting arguments to work
321 format_args!($($fmt_args)*),
322 module_path!(),
323 line!(),
324 )
325 )
326 };
327 }