Skip to content

refactor(mstsgu): derive Display and Error for GwErrorKind via thiserror#1258

Open
Greg Lamberson (glamberson) wants to merge 1 commit into
Devolutions:masterfrom
lamco-admin:feat/mstsgu-thiserror-derive
Open

refactor(mstsgu): derive Display and Error for GwErrorKind via thiserror#1258
Greg Lamberson (glamberson) wants to merge 1 commit into
Devolutions:masterfrom
lamco-admin:feat/mstsgu-thiserror-derive

Conversation

@glamberson
Copy link
Copy Markdown
Contributor

Refs #1257.

First proof-of-concept for the broader thiserror migration proposed in #1257. GwErrorKind is the smallest hand-written *ErrorKind enum in the workspace at 7 variants, so it is suitable for verifying that the migration is byte-identity-preserving and that the workspace thiserror dep lands cleanly.

What this changes

Replaces the hand-written impl Display for GwErrorKind and impl core::error::Error for GwErrorKind blocks with #[derive(thiserror::Error)] and per-variant #[error("...")] attributes. Adds thiserror = "2" to crates/ironrdp-mstsgu/Cargo.toml as a direct dependency, following the same pattern that ironrdp-pdu already uses for its internal thiserror types.

Public API impact

None. The pub type Error = ironrdp_error::Error<GwErrorKind> alias and the GwErrorExt::custom() helper are unchanged. Consumers see no source-level break.

Display byte-identity verification

Verified via cargo expand. Both the prior hand-written implementation and the thiserror-derived implementation call formatter.write_str("literal") with the same string for each of the 7 variants:

Variant String
InvalidGwTarget "invalid GW Target"
Connect "connection error"
PacketEof "PacketEOF"
UnsupportedFeature "unsupported feature"
Custom "custom"
Encode "encode"
Decode "decode"

Verification

  • cargo xtask check fmt: clean
  • cargo xtask check lints: clean
  • cargo xtask check locks: clean
  • cargo xtask check typos: clean
  • cargo xtask check tests: clean

MSRV

Unaffected. thiserror 2.0 requires Rust 1.61, well below IronRDP's MSRV of 1.89.

Refs Devolutions#1257 (proof-of-concept for the broader thiserror migration).

Replace the hand-written `impl Display for GwErrorKind` and
`impl core::error::Error for GwErrorKind` blocks with `#[derive(thiserror::Error)]`
and per-variant `#[error("...")]` attributes.

GwErrorKind has 7 variants and is the smallest hand-written *ErrorKind
enum in the workspace, so it is suitable as the proof-of-concept that:

- Display output is byte-identical (verified via cargo expand: both
  implementations call `formatter.write_str("literal")` with the same
  string for each variant).
- The workspace `thiserror` dependency lands cleanly. ironrdp-pdu
  already pins thiserror = "2.0" for some internal types; this PR adds
  the same direct dep to ironrdp-mstsgu following Devolutions' stated
  preference for per-crate (non-workspace.dependencies) entries.
- MSRV is unaffected (thiserror 2.0 needs Rust 1.61, IronRDP MSRV is 1.89).

Public API impact: none. The `pub type Error = ironrdp_error::Error<GwErrorKind>`
alias and the `GwErrorExt::custom()` helper are unchanged. Consumers of
`Error` see no source-level break.

Verification:
- cargo xtask check fmt: clean
- cargo xtask check lints: clean
- cargo xtask check locks: Cargo.lock updated and included in this commit
- cargo xtask check typos: clean
- cargo xtask check tests: clean
- cargo expand inspection: Display impl byte-identical to prior hand-written
  version for all 7 variants
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant