Skip to content

Commit 4f960c2

Browse files
ramyak-mehralauralt
authored andcommitted
Implement From<BackendError> for Error
Signed-off-by: Ramyak Mehra <rmehra_be19@thapar.edu>
1 parent 1c547f8 commit 4f960c2

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/lib.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,18 @@ impl Display for Error {
272272
}
273273
}
274274

275+
impl From<BackendError> for Error {
276+
fn from(value: BackendError) -> Self {
277+
Self::Backend(value)
278+
}
279+
}
280+
#[cfg(feature = "json")]
281+
impl From<JsonFrontendError> for Error {
282+
fn from(value: JsonFrontendError) -> Self {
283+
Self::JsonFrontend(value)
284+
}
285+
}
286+
275287
/// Apply a BPF filter to the calling thread.
276288
///
277289
/// # Arguments
@@ -325,14 +337,13 @@ pub fn apply_filter(bpf_filter: BpfProgramRef) -> Result<()> {
325337
#[cfg(feature = "json")]
326338
pub fn compile_from_json<R: Read>(reader: R, arch: TargetArch) -> Result<BpfMap> {
327339
// Run the frontend.
328-
let seccomp_filters: HashMap<String, SeccompFilter> = JsonCompiler::new(arch)
329-
.compile(reader)
330-
.map_err(Error::JsonFrontend)?;
340+
let seccomp_filters: HashMap<String, SeccompFilter> =
341+
JsonCompiler::new(arch).compile(reader)?;
331342

332343
// Run the backend.
333344
let mut bpf_data: BpfMap = BpfMap::with_capacity(seccomp_filters.len());
334345
for (name, seccomp_filter) in seccomp_filters {
335-
bpf_data.insert(name, seccomp_filter.try_into().map_err(Error::Backend)?);
346+
bpf_data.insert(name, seccomp_filter.try_into()?);
336347
}
337348

338349
Ok(bpf_data)

0 commit comments

Comments
 (0)