From 8439aeb7cf5e46b96b58e281773c33bdb45f40a4 Mon Sep 17 00:00:00 2001 From: Tamo Date: Wed, 29 Jan 2025 11:51:06 +0100 Subject: [PATCH] improve error message in case of unexpected panic while processing tasks --- crates/index-scheduler/src/error.rs | 8 ++++---- crates/index-scheduler/src/scheduler/mod.rs | 15 ++++++++++++++- .../src/scheduler/process_batch.rs | 13 +++++++++++-- .../index_creation_failed.snap | 2 +- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/crates/index-scheduler/src/error.rs b/crates/index-scheduler/src/error.rs index d3feecd73..e749a1bcb 100644 --- a/crates/index-scheduler/src/error.rs +++ b/crates/index-scheduler/src/error.rs @@ -127,8 +127,8 @@ pub enum Error { _ => format!("{error}") })] Milli { error: milli::Error, index_uid: Option }, - #[error("An unexpected crash occurred when processing the task.")] - ProcessBatchPanicked, + #[error("An unexpected crash occurred when processing the task: {0}")] + ProcessBatchPanicked(String), #[error(transparent)] FileStore(#[from] file_store::Error), #[error(transparent)] @@ -196,7 +196,7 @@ impl Error { | Error::Dump(_) | Error::Heed(_) | Error::Milli { .. } - | Error::ProcessBatchPanicked + | Error::ProcessBatchPanicked(_) | Error::FileStore(_) | Error::IoError(_) | Error::Persist(_) @@ -257,7 +257,7 @@ impl ErrorCode for Error { Error::NoSpaceLeftInTaskQueue => Code::NoSpaceLeftOnDevice, Error::Dump(e) => e.error_code(), Error::Milli { error, .. } => error.error_code(), - Error::ProcessBatchPanicked => Code::Internal, + Error::ProcessBatchPanicked(_) => Code::Internal, Error::Heed(e) => e.error_code(), Error::HeedTransaction(e) => e.error_code(), Error::FileStore(e) => e.error_code(), diff --git a/crates/index-scheduler/src/scheduler/mod.rs b/crates/index-scheduler/src/scheduler/mod.rs index eddf8fba7..90c9584f7 100644 --- a/crates/index-scheduler/src/scheduler/mod.rs +++ b/crates/index-scheduler/src/scheduler/mod.rs @@ -172,7 +172,20 @@ impl IndexScheduler { cloned_index_scheduler.process_batch(batch, processing_batch, progress) }) .unwrap(); - handle.join().unwrap_or(Err(Error::ProcessBatchPanicked)) + + match handle.join() { + Ok(ret) => ret, + Err(panic) => { + let msg = match panic.downcast_ref::<&'static str>() { + Some(s) => *s, + None => match panic.downcast_ref::() { + Some(s) => &s[..], + None => "Box", + }, + }; + Err(Error::ProcessBatchPanicked(msg.to_string())) + } + } }) }; diff --git a/crates/index-scheduler/src/scheduler/process_batch.rs b/crates/index-scheduler/src/scheduler/process_batch.rs index 623bdeb53..21233429c 100644 --- a/crates/index-scheduler/src/scheduler/process_batch.rs +++ b/crates/index-scheduler/src/scheduler/process_batch.rs @@ -326,8 +326,17 @@ impl IndexScheduler { match ret { Ok(Ok(())) => (), Ok(Err(e)) => return Err(Error::DatabaseUpgrade(Box::new(e))), - Err(_e) => { - return Err(Error::DatabaseUpgrade(Box::new(Error::ProcessBatchPanicked))); + Err(e) => { + let msg = match e.downcast_ref::<&'static str>() { + Some(s) => *s, + None => match e.downcast_ref::() { + Some(s) => &s[..], + None => "Box", + }, + }; + return Err(Error::DatabaseUpgrade(Box::new(Error::ProcessBatchPanicked( + msg.to_string(), + )))); } } diff --git a/crates/index-scheduler/src/scheduler/snapshots/test_failure.rs/panic_in_process_batch_for_index_creation/index_creation_failed.snap b/crates/index-scheduler/src/scheduler/snapshots/test_failure.rs/panic_in_process_batch_for_index_creation/index_creation_failed.snap index 3f3a6f769..b0c450092 100644 --- a/crates/index-scheduler/src/scheduler/snapshots/test_failure.rs/panic_in_process_batch_for_index_creation/index_creation_failed.snap +++ b/crates/index-scheduler/src/scheduler/snapshots/test_failure.rs/panic_in_process_batch_for_index_creation/index_creation_failed.snap @@ -7,7 +7,7 @@ snapshot_kind: text [] ---------------------------------------------------------------------- ### All Tasks: -0 {uid: 0, batch_uid: 0, status: failed, error: ResponseError { code: 200, message: "An unexpected crash occurred when processing the task.", error_code: "internal", error_type: "internal", error_link: "https://docs.meilisearch.com/errors#internal" }, details: { primary_key: Some("mouse") }, kind: IndexCreation { index_uid: "catto", primary_key: Some("mouse") }} +0 {uid: 0, batch_uid: 0, status: failed, error: ResponseError { code: 200, message: "An unexpected crash occurred when processing the task: simulated panic", error_code: "internal", error_type: "internal", error_link: "https://docs.meilisearch.com/errors#internal" }, details: { primary_key: Some("mouse") }, kind: IndexCreation { index_uid: "catto", primary_key: Some("mouse") }} ---------------------------------------------------------------------- ### Status: enqueued []