rust-vmm / seccompiler

Provides easy-to-use Linux seccomp-bpf jailing.
https://crates.io/crates/seccompiler
Apache License 2.0
70 stars 10 forks source link

Implement From<BackendError> for Error #31

Closed andreeaflorescu closed 2 years ago

andreeaflorescu commented 2 years ago

Without this we need to add boiler plate code when creating custom filters:

....
    SeccompFilter::new(
        rules.into_iter().collect(),
        SeccompAction::Trap,
        SeccompAction::Allow,
        ARCH.try_into().unwrap(),
    )
    .map_err(Error::Backend)?
    .try_into()
    .map_err(Error::Backend)

If we implement From, then this could be simplified by just having:

    SeccompFilter::new(
        rules.into_iter().collect(),
        SeccompAction::Trap,
        SeccompAction::Allow,
        ARCH.try_into().unwrap(),
    )?
    .try_into()
ramyak-mehra commented 2 years ago

Do you want something like this? @andreeaflorescu

 impl From<BackendError> for Error {
    fn from(value: BackendError) -> Self {
        Self::Backend(value)
    }
}
andreeaflorescu commented 2 years ago

@ramyak-mehra yes. And the same can also be implemented for JsonFrontendError. Then, you should also check in the code where the errors are used because you can already do some simplifications.