Skip to content

fix(error): box diagnostic metadata to shrink Error<Kind> size#1269

Merged
Benoît Cortier (CBenoit) merged 3 commits into
masterfrom
fix/smaller-error
May 14, 2026
Merged

fix(error): box diagnostic metadata to shrink Error<Kind> size#1269
Benoît Cortier (CBenoit) merged 3 commits into
masterfrom
fix/smaller-error

Conversation

@CBenoit
Copy link
Copy Markdown
Member

Move context, location, and source into a heap-allocated ErrorMeta struct so that Error holds only kind on the stack. This eliminates the size cascade that caused ConnectorError to exceed clippy's 128-byte threshold (it was raised to 152 to accommodate the Location field).

Error construction is already #[cold], so the single Box allocation per error is acceptable.

Move context, location, and source into a heap-allocated ErrorMeta struct
so that Error<Kind> holds only kind on the stack. This eliminates the
size cascade that caused ConnectorError to exceed clippy's 128-byte threshold
(it was raised to 152 to accommodate the Location field).

Error construction is already #[cold], so the single Box allocation per
error is acceptable.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR restructures ironrdp_error::Error<Kind> so that diagnostic metadata (context, call-site location, and optional source error) is stored in a heap-allocated ErrorMeta, keeping Error<Kind> itself small and avoiding large-error-size cascades in downstream error enums.

Changes:

  • Introduces an ErrorMeta struct (behind Box) and moves diagnostic fields into it when alloc is enabled.
  • Updates Error<Kind> construction, Debug/Display, and source chaining to use the boxed metadata.
  • Removes the custom clippy.toml large-error-threshold override now that the error size is expected to be below the default limit.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
crates/ironrdp-error/src/lib.rs Boxes diagnostic metadata to reduce Error<Kind> stack size; adjusts formatting and source chaining accordingly.
clippy.toml Drops the previously raised large-error-threshold configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/ironrdp-error/src/lib.rs
Comment thread crates/ironrdp-error/src/lib.rs Outdated
@glamberson
Copy link
Copy Markdown
Contributor

I saw this come in this morning. The Box layout is the right move.

I'll rebase #1266 onto this. The Option I proposed there fits as a fourth field on ErrorMeta, which dissolves the threshold bump that was the awkward part of that PR. I'll mark #1266 as depending on this once I push. If you don't want position metadata at all, withdrawal is fine.

Greg Lamberson (glamberson) pushed a commit to lamco-admin/IronRDP that referenced this pull request May 13, 2026
…ind>

Adds two composable builder methods to ironrdp-error::Error<Kind> that
record optional positional metadata: Error::at_offset records a byte
offset in the input stream, and Error::in_field records a symbolic field
or sub-PDU name. Both are optional, both compose, and both are surfaced
in Display output when present. Position lives as a fourth field on
ErrorMeta (alongside context, location, source) so it carries zero size
cost on Result-Ok paths and is available only when the alloc feature is
enabled.

Refs Devolutions#1257, Devolutions#1120. Depends on Devolutions#1269.
@CBenoit Benoît Cortier (CBenoit) merged commit 2e2699d into master May 14, 2026
9 of 10 checks passed
@CBenoit Benoît Cortier (CBenoit) deleted the fix/smaller-error branch May 14, 2026 10:57
Greg Lamberson (glamberson) pushed a commit to lamco-admin/IronRDP that referenced this pull request May 14, 2026
…ind>

Adds two composable builder methods to ironrdp-error::Error<Kind> that
record optional positional metadata: Error::at_offset records a byte
offset in the input stream, and Error::in_field records a symbolic field
or sub-PDU name. Both are optional, both compose, and both are surfaced
in Display output when present. Position lives as a fourth field on
ErrorMeta (alongside context, location, source) so it carries zero size
cost on Result-Ok paths and is available only when the alloc feature is
enabled.

Refs Devolutions#1257, Devolutions#1120. Depends on Devolutions#1269.
@CBenoit
Copy link
Copy Markdown
Member Author

I saw this come in this morning. The Box layout is the right move.

I'll rebase #1266 onto this. The Option I proposed there fits as a fourth field on ErrorMeta, which dissolves the threshold bump that was the awkward part of that PR. I'll mark #1266 as depending on this once I push. If you don't want position metadata at all, withdrawal is fine.

Hey! Thank you; yes that’s exactly what I had in mind. I saw that we were growing the size of the main error type a bit too much, but I think this new approach will allow us to store more metadata without feeling bad about it 🙂

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.

5 participants