Skip to main content

ironrdp-error

A lightweight, no_std-compatible generic error type used throughout the IronRDP project.

Overview

The ironrdp-error crate provides a flexible Error<Kind> type that combines a static context string with a user-defined error kind enum. It supports optional error chaining through source errors and works in no_std environments with or without allocation. Source: crates/ironrdp-error/

Features

  • Generic Error Kind: Parameterized by user-defined error kind enums
  • Static Context: Zero-allocation context strings using &'static str
  • Source Chaining: Optional error source tracking (requires alloc feature)
  • no_std Support: Works in embedded and bare-metal environments
  • Conversion Support: Convert between different error kinds

Feature Flags

API Reference

Error<Kind>

Generic error type combining context and kind.

Construction

Methods

ErrorReport

Wrapper for formatted error output including full source chain.
The ErrorReport type implements Display and formats the error with all causes in the chain.

Error Source Trait

Source Trait

Abstraction over error sources that works in both std and no_std environments.
All types implementing the appropriate bounds automatically implement Source.

Usage Examples

Basic Error Handling

Error Chaining

Converting Error Kinds

no_std Usage

Integration with IronRDP

Throughout IronRDP, crates define their own error kind enums and use ironrdp_error::Error as the error type:

IronRDP Connector Errors

IronRDP Session Errors

IronRDP PDU Errors

Context Best Practices

Context strings should:
  • Be lowercase snake_case or function names
  • Describe the operation that failed
  • Be static strings (zero allocation)
  • Be concise (used as a prefix)
Good examples:
  • "connect"
  • "send_request"
  • "decode_packet"
  • "establish_channel"
Avoid:
  • Complete sentences
  • Duplicating error kind information
  • Dynamic strings

Display Format

The error displays as [context] kind:

Conversion to std::io::Error

When the std feature is enabled, Error<Kind> can be converted to std::io::Error:

Dependencies

  • core: Rust core library (always available)
  • alloc: Allocation support (optional, for error sources in no_std)
All IronRDP crates use ironrdp-error for error handling:
  • ironrdp-core: Core encoding/decoding errors
  • ironrdp-pdu: PDU parsing errors
  • ironrdp-connector: Connection establishment errors
  • ironrdp-session: Session management errors
  • ironrdp-svc: Static virtual channel errors
  • ironrdp-dvc: Dynamic virtual channel errors

Design Rationale

Why Generic Error Kind?

Rather than a single global error enum, Error<Kind> allows each crate to define its own error taxonomy while sharing the error infrastructure (context, sources, reporting).

Why Static Context?

Static context strings have zero runtime cost and don’t require allocations, making them suitable for performance-critical and no_std code paths.

Why Optional Sources?

Error sources require allocation but provide valuable debugging information. Making them optional via feature flags allows usage in constrained environments while supporting rich error reports where possible.