Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement From<BackendError> for Error #31

Closed
andreeaflorescu opened this issue Nov 4, 2021 · 2 comments · Fixed by #38
Closed

Implement From<BackendError> for Error #31

andreeaflorescu opened this issue Nov 4, 2021 · 2 comments · Fixed by #38
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@andreeaflorescu
Copy link
Member

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()
@andreeaflorescu andreeaflorescu added enhancement New feature or request good first issue Good for newcomers labels Nov 4, 2021
@ramyak-mehra
Copy link
Contributor

ramyak-mehra commented Apr 6, 2022

Do you want something like this? @andreeaflorescu

 impl From<BackendError> for Error {
    fn from(value: BackendError) -> Self {
        Self::Backend(value)
    }
}

@andreeaflorescu
Copy link
Member Author

@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.

@alindima alindima linked a pull request Apr 11, 2022 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants