Back to all reviewers

Handle errors by criticality

influxdata/influxdb
Based on 5 comments
Rust

Choose error handling strategies based on operation criticality: 1. For critical operations that could corrupt data or state: - Use assertions/panics to fail fast

Error Handling Rust

Reviewer Prompt

Choose error handling strategies based on operation criticality:

  1. 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");
      
  2. 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;
             }
         }
       }
      }
      
  3. 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.

5
Comments Analyzed
Rust
Primary Language
Error Handling
Category

Source Discussions