Skip to content

Commit 1e21f35

Browse files
Greg Lambersonlamco-office
authored andcommitted
feat(error): record byte offset on decode and encode error variants
Reshapes the position-aware error approach per Devolutions#1266 review feedback. Moves position metadata out of the foundational `ironrdp-error` crate and onto the decode and encode `*ErrorKind` enum variants where it actually applies. Previously this PR added an optional `ErrorPosition { offset, field }` slot to `Error<Kind>`'s `ErrorMeta`, paying a metadata slot on every error in the workspace to serve only the decode and encode surfaces. The new shape places a non-optional `offset: usize` on each variant that can know one: - `DecodeErrorKind::{NotEnoughBytes, InvalidField, UnexpectedMessageType, UnsupportedVersion, UnsupportedValue}` gain `offset: usize` - `EncodeErrorKind::*` mirrors the same shape for encode-side errors - `*::Other` is unchanged; producers of `Other` typically lack stream-cursor access and the variant exists precisely for those cases The `in_field` dotted-path use case is dropped from this PR per the same review: `Error::set_context` already covers it. No parallel structured field-tracking channel is introduced. Trait and macro changes: - `NotEnoughBytesErr`, `InvalidFieldErr`, `UnexpectedMessageTypeErr`, `UnsupportedVersionErr`, `UnsupportedValueErr` all take an additional `offset: usize` parameter - The five corresponding `*_err!` macros gain `at:` and `in:` prefixes for explicit offset and cursor-extracted offset respectively - `OtherErr` and `other_err!` are unchanged - `cast_length!` and `cast_int!` macros pass `0` to the new offset slot (the macros do not have stream-cursor access) Call-site migration: - All 84 affected files updated to pass an explicit offset - Most existing call sites pass `0` (the documented "offset unknown" sentinel) since the cursor is not always in lexical scope at the call site - Cursor-aware sites can opt in via the new `in: cursor` macro syntax - A workspace sweep upgrading `at: 0` to `in: cursor` where applicable is a follow-up Display output includes the offset when known: `invalid \`field\` at offset 47: reason` Refs Devolutions#1257, Devolutions#1120. Supersedes the cross-cutting `ErrorPosition` approach that was on this branch before today's review.
1 parent 0e10d37 commit 1e21f35

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

  • crates/ironrdp-rdpdr/src/pdu

crates/ironrdp-rdpdr/src/pdu/efs.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3044,9 +3044,11 @@ impl ServerDriveQueryVolumeInformationRequest {
30443044
| FileSystemInformationClassLevel::FILE_FS_FULL_SIZE_INFORMATION
30453045
| FileSystemInformationClassLevel::FILE_FS_DEVICE_INFORMATION => {}
30463046
_ => {
3047-
return Err(invalid_field_err!( "ServerDriveQueryVolumeInformationRequest::decode",
3047+
return Err(
3048+
invalid_field_err!( "ServerDriveQueryVolumeInformationRequest::decode",
30483049
"fs_info_class_lvl",
3049-
"received invalid level", at: 0));
3050+
"received invalid level", at: 0),
3051+
);
30503052
}
30513053
}
30523054

0 commit comments

Comments
 (0)