Skip to content

Commit 7c437e3

Browse files
committed
models/version: Fix published_by() error handling
If there is an error in this query we shouldn't silently fail and return `None`, we should propagate the error instead and let the caller decide what to do.
1 parent 40d1afb commit 7c437e3

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/controllers/version/metadata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub async fn show(
104104
spawn_blocking(move || {
105105
let conn: &mut AsyncConnectionWrapper<_> = &mut conn.into();
106106

107-
let published_by = version.published_by(conn);
107+
let published_by = version.published_by(conn)?;
108108
let actions = VersionOwnerAction::by_version(conn, &version)?;
109109

110110
let version = EncodableVersion::from(version, &krate.name, published_by, actions);
@@ -142,7 +142,7 @@ pub async fn update(
142142
update_request.version.yank_message,
143143
)?;
144144

145-
let published_by = version.published_by(conn);
145+
let published_by = version.published_by(conn)?;
146146
let actions = VersionOwnerAction::by_version(conn, &version)?;
147147
let updated_version = EncodableVersion::from(version, &krate.name, published_by, actions);
148148
Ok(Json(json!({ "version": updated_version })))

src/models/version.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ impl Version {
4949

5050
/// Gets the User who ran `cargo publish` for this version, if recorded.
5151
/// Not for use when you have a group of versions you need the publishers for.
52-
pub fn published_by(&self, conn: &mut impl Conn) -> Option<User> {
52+
pub fn published_by(&self, conn: &mut impl Conn) -> QueryResult<Option<User>> {
5353
use diesel::RunQueryDsl;
5454

5555
match self.published_by {
56-
Some(pb) => users::table.find(pb).first(conn).ok(),
57-
None => None,
56+
Some(pb) => users::table.find(pb).first(conn).optional(),
57+
None => Ok(None),
5858
}
5959
}
6060

0 commit comments

Comments
 (0)