Module error

Module error 

Source
Expand description

§Error Types

Comprehensive error handling for the network protocol.

This module defines all error variants that can occur during protocol operations, from low-level I/O errors to high-level protocol violations.

§Error Categories

  • I/O Errors: Network and file system failures
  • Protocol Errors: Invalid packets, handshake failures, timeouts
  • Cryptographic Errors: Encryption/decryption failures
  • TLS Errors: Certificate and connection issues
  • Compression Errors: Decompression failures, size limit violations

All errors implement std::error::Error for interoperability.

§Example Usage

use network_protocol::error::{ProtocolError, Result};
use std::fs::File;
use std::io::Read;
use tracing::{info, error};

fn read_file(path: &str) -> Result<String> {
    let mut file = File::open(path).map_err(ProtocolError::Io)?;
    let mut contents = String::new();
    file.read_to_string(&mut contents).map_err(ProtocolError::Io)?;
    Ok(contents)
}

fn main() {
    match read_file("example.txt") {
        Ok(contents) => info!(contents, "Successfully read file"),
        Err(e) => error!(error=%e, "Error reading file"),
    }
}

Enums§

ProtocolError

Type Aliases§

Result
Type alias for Results using ProtocolError