Module error

Source
Expand description

Error types for the VPR (Virtual Patient Record) system.

This module defines the comprehensive error handling for all operations in the VPR core crate. The PatientError enum encompasses all possible failure modes across the system’s functionality, including patient data management, Git versioning, cryptographic operations, and external integrations.

§Error Categories

Errors are organized into logical categories:

  • Input Validation: Invalid user inputs, malformed data, or constraint violations
  • File System Operations: Directory creation, file I/O, and storage management
  • Serialization: JSON and YAML encoding/decoding failures
  • Git Operations: Repository management, commits, signatures, and version control
  • Cryptographic Operations: ECDSA signing, key parsing, certificate validation
  • Author Validation: Commit author metadata and registration verification
  • External Integrations: OpenEHR system interactions

§Error Handling Philosophy

VPR follows defensive programming principles with comprehensive error handling:

  • Fail Fast: Invalid inputs and configuration are rejected early
  • Detailed Diagnostics: Errors include context and source information where possible
  • Recovery Guidance: Error messages are designed to be actionable for developers and operators
  • Type Safety: The PatientResult type alias provides consistent error propagation

§Usage

Most VPR operations return PatientResult<T> to indicate success or failure:

use vpr_core::PatientResult;

fn some_operation() -> PatientResult<String> {
    // Operation that might fail
    Ok("success".to_string())
}

Errors can be handled using standard Rust error handling patterns:

match some_operation() {
    Ok(result) => println!("Success: {}", result),
    Err(PatientError::InvalidInput(msg)) => eprintln!("Invalid input: {}", msg),
    Err(other) => eprintln!("Other error: {}", other),
}

Enums§

PatientError
Comprehensive error type for all VPR operations.

Type Aliases§

PatientResult
Type alias for Results that can fail with PatientError.