refactor(error): remove CatchAllKind

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau
2024-08-30 00:05:16 -04:00
committed by Benoît Cortier
parent 278a0506c2
commit f6a45ca24b
11 changed files with 11 additions and 88 deletions
-4
View File
@@ -189,7 +189,3 @@ pub fn decode_io_channel(ctx: SendDataIndicationCtx<'_>) -> ConnectorResult<IoCh
)),
}
}
impl ironrdp_error::legacy::CatchAllKind for crate::ConnectorErrorKind {
const CATCH_ALL_VALUE: Self = crate::ConnectorErrorKind::General;
}
-27
View File
@@ -160,30 +160,3 @@ where
Ok(())
}
}
/// Temporary compatibility traits to smooth transition from old style
#[cfg(feature = "std")]
#[doc(hidden)]
pub mod legacy {
#[doc(hidden)]
pub trait CatchAllKind {
const CATCH_ALL_VALUE: Self;
}
#[doc(hidden)]
pub trait ErrorContext: std::error::Error {
fn context(&self) -> &'static str;
}
#[doc(hidden)]
impl<E, Kind> From<E> for crate::Error<Kind>
where
E: ErrorContext + Send + Sync + 'static,
Kind: CatchAllKind,
{
#[cold]
fn from(error: E) -> Self {
Self::new(error.context(), Kind::CATCH_ALL_VALUE).with_source(error)
}
}
}
-6
View File
@@ -447,12 +447,6 @@ pub enum ZgfxError {
TokenBitsNotFound,
}
impl ironrdp_error::legacy::ErrorContext for ZgfxError {
fn context(&self) -> &'static str {
"zgfx"
}
}
#[cfg(test)]
mod tests {
use super::*;
-7
View File
@@ -285,10 +285,3 @@ pub enum RfxError {
#[error("got invalid channel height: {0}")]
InvalidChannelHeight(i16),
}
#[cfg(feature = "std")]
impl ironrdp_error::legacy::ErrorContext for RfxError {
fn context(&self) -> &'static str {
"RFX"
}
}
-5
View File
@@ -418,9 +418,4 @@ mod legacy {
#[error("received invalid action code: {0}")]
InvalidActionCode(u8),
}
#[cfg(feature = "std")]
impl ironrdp_error::legacy::CatchAllKind for crate::PduErrorKind {
const CATCH_ALL_VALUE: Self = crate::PduErrorKind::Custom;
}
}
-7
View File
@@ -1185,11 +1185,4 @@ mod legacy {
io::Error::new(io::ErrorKind::Other, format!("MCS Connection Sequence error: {e}"))
}
}
#[cfg(feature = "std")]
impl ironrdp_error::legacy::ErrorContext for McsError {
fn context(&self) -> &'static str {
"mcs"
}
}
}
-7
View File
@@ -113,10 +113,3 @@ impl From<RdpError> for io::Error {
io::Error::new(io::ErrorKind::Other, format!("RDP Connection Sequence error: {e}"))
}
}
#[cfg(feature = "std")]
impl ironrdp_error::legacy::ErrorContext for RdpError {
fn context(&self) -> &'static str {
"RDP"
}
}
@@ -264,13 +264,6 @@ impl From<LicensingErrorMessage> for ServerLicenseError {
}
}
#[cfg(feature = "std")]
impl ironrdp_error::legacy::ErrorContext for ServerLicenseError {
fn context(&self) -> &'static str {
"server license"
}
}
#[derive(Debug, PartialEq)]
pub struct BlobHeader {
pub blob_type: BlobType,
-7
View File
@@ -114,10 +114,3 @@ impl From<ChannelError> for io::Error {
io::Error::new(io::ErrorKind::Other, format!("Virtual channel error: {e}"))
}
}
#[cfg(feature = "std")]
impl ironrdp_error::legacy::ErrorContext for ChannelError {
fn context(&self) -> &'static str {
"virtual channel error"
}
}
-4
View File
@@ -18,7 +18,3 @@ impl From<ironrdp_connector::ConnectorErrorKind> for crate::SessionErrorKind {
pub(crate) fn map_error(error: ironrdp_connector::ConnectorError) -> SessionError {
error.into_other_kind()
}
impl ironrdp_error::legacy::CatchAllKind for crate::SessionErrorKind {
const CATCH_ALL_VALUE: Self = crate::SessionErrorKind::General;
}
+11 -7
View File
@@ -45,7 +45,8 @@ impl DecodingContext {
input: &mut &[u8],
) -> SessionResult<(FrameId, InclusiveRectangle)> {
loop {
let block_header = rfx::BlockHeader::from_buffer_consume(input)?;
let block_header =
rfx::BlockHeader::from_buffer_consume(input).map_err(|e| custom_err!("decode header", e))?;
match block_header.ty {
rfx::BlockType::Sync => {
self.process_sync(input, block_header)?;
@@ -65,7 +66,8 @@ impl DecodingContext {
}
fn process_sync(&mut self, input: &mut &[u8], header: rfx::BlockHeader) -> SessionResult<()> {
let _sync = rfx::SyncPdu::from_buffer_consume_with_header(input, header)?;
let _sync =
rfx::SyncPdu::from_buffer_consume_with_header(input, header).map_err(|e| custom_err!("decode sync", e))?;
self.process_headers(input)
}
@@ -75,7 +77,7 @@ impl DecodingContext {
// headers can appear in any order: CodecVersions, Channels, Context
for _ in 0..3 {
match Headers::from_buffer_consume(input)? {
match Headers::from_buffer_consume(input).map_err(|e| custom_err!("decode headers", e))? {
Headers::Context(c) => context = Some(c),
Headers::Channels(c) => channels = Some(c),
Headers::CodecVersions(_) => (),
@@ -107,10 +109,12 @@ impl DecodingContext {
let height = channel.height.as_u16();
let entropy_algorithm = self.context.entropy_algorithm;
let frame_begin = rfx::FrameBeginPdu::from_buffer_consume_with_header(input, header)?;
let mut region = rfx::RegionPdu::from_buffer_consume(input)?;
let tile_set = rfx::TileSetPdu::from_buffer_consume(input)?;
let _frame_end = rfx::FrameEndPdu::from_buffer_consume(input)?;
let frame_begin = rfx::FrameBeginPdu::from_buffer_consume_with_header(input, header)
.map_err(|e| custom_err!("decode frame_begin", e))?;
let mut region = rfx::RegionPdu::from_buffer_consume(input).map_err(|e| custom_err!("decode region", e))?;
let tile_set = rfx::TileSetPdu::from_buffer_consume(input).map_err(|e| custom_err!("decode tile_set", e))?;
let _frame_end =
rfx::FrameEndPdu::from_buffer_consume(input).map_err(|e| custom_err!("decode frame_end", e))?;
if region.rectangles.is_empty() {
region.rectangles = vec![RfxRectangle {