Skip to content

ironrdp-server: replace anyhow::Result with typed error in public API #1209

Description

The ironrdp-server public API uses anyhow::Result for trait signatures and method return types:

  • RdpServerDisplayUpdates::next_update() -> Result<Option<DisplayUpdate>>
  • RdpServerDisplay::updates() -> Result<Box<dyn RdpServerDisplayUpdates>>
  • RdpServer::run() -> Result<()>
  • RdpServer::run_connection() -> Result<()>
  • ConnectionHandler::on_disconnected(error: Option<&anyhow::Error>)
  • TlsIdentityCtx::init_from_paths() -> anyhow::Result<Self>
  • EchoServerHandle::send_request() -> Result<()>

The rest of the IronRDP library crates use typed errors via ironrdp_error::Error<Kind> (e.g. SessionError, ConnectorError). Using anyhow in the server crate means consumers can't pattern-match on error kinds, and every consumer takes an implicit dependency on the anyhow crate.

A ServerError / ServerErrorKind type following the same pattern as ironrdp-session and ironrdp-connector would bring the server crate in line with the rest of the library. Rough sketch of what that would look like:

pub type ServerError = ironrdp_error::Error<ServerErrorKind>;
pub type ServerResult<T> = Result<T, ServerError>;

#[non_exhaustive]
pub enum ServerErrorKind {
    Io,
    Pdu,
    Encode,
    Security,
    Channel,
    General,
    Custom,
}

Files that would need changes:

  • New error.rs module with the type definitions and ServerErrorExt convenience trait
  • display.rs: trait signatures (next_update, updates)
  • server.rs: run(), run_connection(), ConnectionHandler::on_disconnected
  • echo.rs: send_request
  • helper.rs: init_from_paths, make_acceptor
  • builder.rs: noop trait impls (NoopDisplayUpdates, NoopDisplay)
  • encoder/mod.rs: internal anyhow usage could stay or migrate
  • Example server (examples/server.rs): trait impl return types
  • Doc examples in display.rs

The main complication is the consumer-implemented traits (RdpServerDisplay, RdpServerDisplayUpdates). Changing their return types is semver-breaking and requires all downstream implementors to update. The Custom variant with with_source() preserves the flexibility consumers currently get from anyhow.

Would this be welcome as a PR? Happy to do the work if so.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions