mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-01-19 23:26:32 +00:00
Improves error handling in the case of missing type
This commit is contained in:
parent
05c1a8899a
commit
25858fc42a
@ -57,6 +57,10 @@ pub enum Error {
|
||||
#[error("no rows returned by a query that expected to return at least one row")]
|
||||
RowNotFound,
|
||||
|
||||
/// Type in query doesn't exist. Likely due to typo or missing user type.
|
||||
#[error("type named {type_name} not found")]
|
||||
TypeNotFound { type_name: String },
|
||||
|
||||
/// Column index was out of bounds.
|
||||
#[error("column index out of bounds: the len is {len}, but the index is {index}")]
|
||||
ColumnIndexOutOfBounds { index: usize, len: usize },
|
||||
|
||||
@ -235,11 +235,13 @@ SELECT oid FROM pg_catalog.pg_type WHERE typname ILIKE $1
|
||||
",
|
||||
)
|
||||
.bind(name)
|
||||
.fetch_one(&mut *self)
|
||||
.await?;
|
||||
.fetch_optional(&mut *self)
|
||||
.await?
|
||||
.ok_or_else(|| Error::TypeNotFound {
|
||||
type_name: String::from(name),
|
||||
})?;
|
||||
|
||||
self.cache_type_oid.insert(name.to_string().into(), oid);
|
||||
|
||||
Ok(oid)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user