Prompt
Choose error handling strategies based on operation criticality:
- For critical operations that could corrupt data or state:
- Use assertions/panics to fail fast
- Example: Validating snapshot details before WAL deletion
// Critical operation - use assert assert_eq!(snapshot_details, details, "Snapshot mismatch before WAL deletion");
- For recoverable operations:
- Return Result/Error types
- Implement retry with backpressure
- Log appropriately (warn for temporary, error for persistent issues)
// Recoverable operation - return Result async fn persist_data(&self) -> Result<(), Error> { loop { match self.try_persist().await { Ok(_) => return Ok(()), Err(e) => { warn!("Temporary persist error, retrying: {}", e); tokio::time::sleep(Duration::from_secs(1)).await; } } } }
- For race conditions and invariant violations:
- Use panic/assert when they indicate programming errors
- Return errors when they represent expected edge cases
This approach ensures critical errors fail fast while allowing recovery from transient failures.