Skip to content

Commit f680208

Browse files
committed
refactor: replace DeserializationError with type alias
The error enum had only 1 element and we can replace it with alias for simplicity. Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent a00964e commit f680208

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/vmm/src/seccomp.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::collections::HashMap;
55
use std::io::Read;
66
use std::sync::Arc;
77

8-
use bincode::{DefaultOptions, Error as BincodeError, Options};
8+
use bincode::{DefaultOptions, Options};
99

1010
/// Each BPF instruction is 8 bytes long and 4 byte aligned.
1111
/// This alignment needs to be satisfied in order for a BPF code to be accepted
@@ -21,6 +21,9 @@ pub type BpfProgramRef<'a> = &'a [BpfInstruction];
2121
/// Type that associates a thread category to a BPF program.
2222
pub type BpfThreadMap = HashMap<String, Arc<BpfProgram>>;
2323

24+
/// Binary filter deserialization errors.
25+
pub type DeserializationError = bincode::Error;
26+
2427
/// Retrieve empty seccomp filters.
2528
pub fn get_empty_filters() -> BpfThreadMap {
2629
let mut map = BpfThreadMap::new();
@@ -30,13 +33,6 @@ pub fn get_empty_filters() -> BpfThreadMap {
3033
map
3134
}
3235

33-
/// Binary filter deserialization errors.
34-
#[derive(Debug, thiserror::Error, displaydoc::Display)]
35-
pub enum DeserializationError {
36-
/// Bincode deserialization failed: {0}
37-
Bincode(BincodeError),
38-
}
39-
4036
/// Deserialize binary with bpf filters
4137
pub fn deserialize_binary<R: Read>(
4238
reader: R,
@@ -50,8 +46,7 @@ pub fn deserialize_binary<R: Read>(
5046
.deserialize_from::<R, HashMap<String, BpfProgram>>(reader),
5147
// No limit is the default.
5248
None => bincode::deserialize_from::<R, HashMap<String, BpfProgram>>(reader),
53-
}
54-
.map_err(DeserializationError::Bincode)?;
49+
}?;
5550

5651
Ok(result
5752
.into_iter()
@@ -169,7 +164,7 @@ mod tests {
169164
// Binary limit too low.
170165
assert!(matches!(
171166
deserialize_binary(&bytes[..], Some(20)).unwrap_err(),
172-
DeserializationError::Bincode(error)
167+
error
173168
if error.to_string() == "the size limit has been reached"
174169
));
175170

0 commit comments

Comments
 (0)