gitbutlerapp/gitbutler · error
handler task panicked
Error message
handler task panicked: {e} What it means
Wraps a JoinError from `tokio::task::spawn_blocking` when the blocking handler function panics. Instead of propagating the panic to the axum worker, the server converts it into a normal Err result that is serialized as a JSON error response via `cmd_result_to_json`.
Solutions
- Check the server logs/panic message for the handler's panic location and fix the underlying bug in that command handler
- Look at the posted JSON params in the request — a malformed or unexpected payload often triggers the unwrap/panic
- Update or file an issue against the specific command handler so it returns Result instead of panicking
- Retry only after fixing; retrying the same request will panic again
Example fix
// before
fn handler(params: Value) -> Result<Value> {
let id = params["id"].as_str().unwrap(); // panics
// after
fn handler(params: Value) -> Result<Value> {
let id = params["id"].as_str()
.ok_or_else(|| anyhow::anyhow!("missing or non-string 'id'"))?; Defensive patterns
Strategy: try-catch
Validate before calling
// client-side: validate params shape before posting
if (typeof params.id !== 'string') throw new Error('id must be a string');
await fetch(url, { method: 'POST', body: JSON.stringify(params) }); Type guard
function isPanicResponse(res: { ok: boolean; body: unknown }): boolean {
return !res.ok || (typeof res.body === 'object' && res.body !== null &&
'message' in res.body && String((res.body as any).message).includes('handler task panicked'));
} Try / catch
const res = await post('/cmd', params);
const body = await res.json();
if (typeof body?.message === 'string' && body.message.startsWith('handler task panicked')) {
reportBug(body.message); // server-side bug, not retryable
} Prevention
- Fix handler unwraps — return Result instead of panicking in blocking handlers
- Log posted params on panic to reproduce
- Add panic hooks in spawn_blocking handlers to capture backtraces
- Keep client/server versions in sync
When it happens
Trigger: Any `but_post`-registered command whose blocking handler function `f` panics (unwrap on None/Err, index out of bounds, explicit panic, assertion failure) while processing the posted JSON params.
Common situations: A command handler hits an unexpected state like a poisoned lock, corrupted repo state, or a serde edge case that unwraps; clients see an HTTP response with 'handler task panicked' instead of a server crash.
Related errors
- failed to create app settings
- failed to create app settings
- GenericFailure
- thread panicked
- a committed transaction always materializes a workspace
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/d47c036ef285fbdd.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-server/src/lib.rs:70
#[derive(Clone)]
struct AppState {
broadcaster: Arc<Mutex<Broadcaster>>,
extra: Extra,
app_settings: AppSettingsWithDiskSync,
}
/// Converts a synchronous command handler into an axum `MethodRouter` that works with
/// `Router::route`.
fn but_post<F, S>(f: F) -> MethodRouter<S, Infallible>
where
F: Fn(serde_json::Value) -> anyhow::Result<serde_json::Value> + Copy + Send + Sync + 'static,
S: Clone + Send + Sync + 'static,
{
post(move |Json(params)| async move {
let res = tokio::task::spawn_blocking(move || f(params))
.await
.unwrap_or_else(|e| Err(anyhow::anyhow!("handler task panicked: {e}")));
cmd_result_to_json(res)
})
}
/// Converts an asynchronous command handler into an axum `MethodRouter` that works with
/// `Router::route`.
fn but_post_async<F, Fut, S>(f: F) -> MethodRouter<S, Infallible>
where
F: Fn(serde_json::Value) -> Fut + Copy + Send + Sync + 'static,
Fut: Future<Output = anyhow::Result<serde_json::Value>> + Send,
S: Clone + Send + Sync + 'static,
{
post(move |Json(params)| async move {
let res = f(params).await;
cmd_result_to_json(res)
})
}
View on GitHub (pinned to 58e5313667)