Improves error handling in the case of missing type

This commit is contained in:
William Hammond 2020-12-13 15:06:19 -05:00 committed by Ryan Leckey
parent 05c1a8899a
commit 25858fc42a
2 changed files with 9 additions and 3 deletions

View File

@ -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 },

View File

@ -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)
}