From 46224806621cb327fb954f83801841cf51bceab2 Mon Sep 17 00:00:00 2001 From: Brad Seiler Date: Fri, 7 Aug 2026 00:48:22 -0400 Subject: [PATCH] fix(media): make upload short-circuit blob key structural Replace the Option + expect("checked above") pattern in both upload short-circuit paths with a filtered if-let binding, so the presence of the blob key is guaranteed structurally instead of by a comment on a non-local invariant. Also collapse the longhand match on existing_write_key into `?`. No behavior change. Signed-off-by: Brad Seiler --- crates/buzz-media/src/upload.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/buzz-media/src/upload.rs b/crates/buzz-media/src/upload.rs index baa15421a..1adbb8f19 100644 --- a/crates/buzz-media/src/upload.rs +++ b/crates/buzz-media/src/upload.rs @@ -95,11 +95,11 @@ where // Idempotent: short-circuit only if BOTH sidecar and blob exist. If the // sidecar exists but the blob is missing, fall through to re-upload. let sidecar_exists = storage.head(&meta_key).await?; - let existing_blob_key = match storage.existing_write_key(ctx, &legacy_key).await { - Ok(key) => key, - Err(error) => return Err(error), - }; - if sidecar_exists && existing_blob_key.is_some() { + let existing_blob_key = storage + .existing_write_key(ctx, &legacy_key) + .await? + .filter(|_| sidecar_exists); + if let Some(existing_blob_key) = existing_blob_key { let meta = storage.get_sidecar(ctx, &sha256).await?; // A re-upload of known bytes is still a distinct upload *event*: no // blob PUT happens, so without this record the uploader would be @@ -114,7 +114,7 @@ where UploadEventFacts { sha256: &sha256, ext: &ext, - blob_key: existing_blob_key.as_deref().expect("checked above"), + blob_key: &existing_blob_key, mime: &mime, size: body.len() as u64, uploaded_at: chrono::Utc::now().timestamp(), @@ -437,11 +437,11 @@ pub async fn process_video_upload( // --- 5. Idempotency check --- let sidecar_exists = storage.head(&meta_key).await?; - let existing_blob_key = match storage.existing_write_key(ctx, &legacy_key).await { - Ok(key) => key, - Err(error) => return Err(error), - }; - if sidecar_exists && existing_blob_key.is_some() { + let existing_blob_key = storage + .existing_write_key(ctx, &legacy_key) + .await? + .filter(|_| sidecar_exists); + if let Some(existing_blob_key) = existing_blob_key { let meta = storage.get_sidecar(ctx, &sha256_hex).await?; // Re-upload of known bytes: still a distinct upload event — see the // buffered path's short-circuit for the rationale. @@ -454,7 +454,7 @@ pub async fn process_video_upload( UploadEventFacts { sha256: &sha256_hex, ext, - blob_key: existing_blob_key.as_deref().expect("checked above"), + blob_key: &existing_blob_key, mime: &mime, size: file_size, uploaded_at: chrono::Utc::now().timestamp(),