Skip to content

rust.spawn_no_error_handling

Stability Medium

Detects tokio::spawn calls where the JoinHandle is ignored, losing task panics.

Ignored spawn results:

  • Silent failures — Task panics are never seen
  • Lost errors — Return values disappear
  • Debugging blind spots — No visibility into task health
  • Resource leaks — Failed tasks may leave resources hanging
// ❌ Before (JoinHandle ignored)
tokio::spawn(async {
risky_operation().await?;
Ok(())
});
// ✅ After (error handling)
let handle = tokio::spawn(async {
risky_operation().await
});
// Check result
match handle.await {
Ok(result) => result?,
Err(e) if e.is_panic() => {
tracing::error!("Task panicked: {:?}", e);
}
Err(e) => {
tracing::error!("Task error: {:?}", e);
}
}
  • tokio::spawn() with ignored return value
  • Fire-and-forget task patterns
  • Missing .await on JoinHandle

Unfault adds proper error handling:

tokio::spawn(async move {
if let Err(e) = operation().await {
tracing::error!("Task failed: {:?}", e);
}
});