Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions crates/client-api/src/routes/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,12 @@ fn map_procedure_error(e: ProcedureCallError, procedure: &str) -> (StatusCode, S
log::info!("Procedure {procedure} could not run because the module is out of energy");
StatusCode::PAYMENT_REQUIRED
}
ProcedureCallError::GuestPanic(_) => {
log::debug!("Guest error while invoking procedure {procedure}: {e:#}");
StatusCode::INTERNAL_SERVER_ERROR
}
ProcedureCallError::InternalError(_) => {
// TODO: May need to split this from module errors vs host errors
log::info!("Internal error while invoking procedure {procedure}: {e:#}");
log::error!("Internal error while invoking procedure {procedure}: {e:#}");
StatusCode::INTERNAL_SERVER_ERROR
}
};
Expand Down Expand Up @@ -2454,6 +2457,21 @@ mod tests {
remove_http_response_size_metric(database_identity);
}

#[test]
fn test_map_procedure_error_distinguishes_guest_panic_and_internal_error() {
let (status, msg) = map_procedure_error(
ProcedureCallError::GuestPanic("panic in guest".to_string()),
"my_proc",
);
assert_eq!(status, StatusCode::INTERNAL_SERVER_ERROR);
assert!(msg.contains("panic in guest"));

let (status, msg) = map_procedure_error(
ProcedureCallError::InternalError("host failure".to_string()),
"my_proc",
);
assert_eq!(status, StatusCode::INTERNAL_SERVER_ERROR);
assert!(msg.contains("host failure"));
fn root_router(root_routes: RootRoutes<DummyState>) -> axum::Router {
let state = DummyState::new();
router_with_root_routes(
Expand Down
2 changes: 2 additions & 0 deletions crates/core/src/host/module_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,8 @@ pub enum ProcedureCallError {
#[error("Procedure terminated due to insufficient budget")]
OutOfEnergy,
#[error("The module instance encountered a fatal error: {0}")]
GuestPanic(String),
#[error("The procedure call encountered an internal error: {0}")]
InternalError(String),
}

Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/host/wasm_common/module_host_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ impl InstanceCommon {
// return Err(ProcedureCallError::OutOfEnergy);
// } else
{
Err(ProcedureCallError::InternalError(format!("{err}")))
Err(ProcedureCallError::GuestPanic(format!("{err}")))
}
}
Ok(return_val) => {
Expand Down