rust.spawn_no_error_handling
Stability
Medium
Detects tokio::spawn calls where the JoinHandle is ignored, losing task panics.
Why It Matters
Section titled “Why It Matters”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
Example
Section titled “Example”// ❌ Before (JoinHandle ignored)tokio::spawn(async { risky_operation().await?; Ok(())});// ✅ After (error handling)let handle = tokio::spawn(async { risky_operation().await});
// Check resultmatch handle.await { Ok(result) => result?, Err(e) if e.is_panic() => { tracing::error!("Task panicked: {:?}", e); } Err(e) => { tracing::error!("Task error: {:?}", e); }}What Unfault Detects
Section titled “What Unfault Detects”tokio::spawn()with ignored return value- Fire-and-forget task patterns
- Missing
.awaiton JoinHandle
Auto-Fix
Section titled “Auto-Fix”Unfault adds proper error handling:
tokio::spawn(async move { if let Err(e) = operation().await { tracing::error!("Task failed: {:?}", e); }});