mkv

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit d363c0034729974dfd03038542d92bb8654f7571
parent e67f476ca474ec26147eef145c9bedf7447a83d6
Author: Silas Brack <silas@teton.ai>
Date:   Sat,  7 Mar 2026 16:06:51 +0100

Remove panics

Diffstat:
Msrc/rebalance.rs | 16++++++++++++++--
Msrc/server.rs | 21+++++++++++++++------
2 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/src/rebalance.rs b/src/rebalance.rs @@ -56,14 +56,26 @@ pub async fn run(args: &Args, dry_run: bool) { let mut errors = 0; for m in &moves { - let src = &m.current_volumes[0]; + let Some(src) = m.current_volumes.first() else { + eprintln!(" SKIP {} : no source volume", m.key); + errors += 1; + continue; + }; let mut copy_ok = true; for dst in &m.to_add { let src_url = format!("{src}/{}", m.key); match client.get(&src_url).send().await { Ok(resp) if resp.status().is_success() => { - let data = resp.bytes().await.unwrap(); + let data = match resp.bytes().await { + Ok(b) => b, + Err(e) => { + eprintln!(" ERROR read body {} from {}: {}", m.key, src, e); + copy_ok = false; + errors += 1; + break; + } + }; let dst_url = format!("{dst}/{}", m.key); if let Err(e) = client.put(&dst_url).body(data).send().await { eprintln!(" ERROR copy {} to {}: {}", m.key, dst, e); diff --git a/src/server.rs b/src/server.rs @@ -20,7 +20,7 @@ pub async fn get_key( Path(key): Path<String>, ) -> Result<Response, AppError> { let record = state.db.get(&key).await?; - let vol = &record.volumes[0]; + let vol = record.volumes.first().ok_or(AppError::NotFound)?; let location = format!("{vol}/{key}"); Ok((StatusCode::FOUND, [(axum::http::header::LOCATION, location)]).into_response()) } @@ -60,9 +60,16 @@ pub async fn put_key( let mut failed = false; for handle in handles { - if let Err(e) = handle.await.unwrap() { - tracing::error!("{e}"); - failed = true; + match handle.await { + Ok(Err(e)) => { + tracing::error!("{e}"); + failed = true; + } + Err(e) => { + tracing::error!("volume write task failed: {e}"); + failed = true; + } + Ok(Ok(())) => {} } } @@ -92,8 +99,10 @@ pub async fn delete_key( handles.push(tokio::spawn(async move { client.delete(&url).send().await })); } for handle in handles { - if let Err(e) = handle.await.unwrap() { - tracing::error!("DELETE from volume failed: {e}"); + match handle.await { + Ok(Err(e)) => tracing::error!("DELETE from volume failed: {e}"), + Err(e) => tracing::error!("volume delete task failed: {e}"), + Ok(Ok(_)) => {} } }