Skip to content

Minor Error API Suggestions #1

@TedDriggs

Description

@TedDriggs

Really excited to see this crate, and very impressed by your work so far.

Reading over the code, I see a few places where the ExtraSafeError could be tweaked to align cleanly with Rust's naming practices.

  1. Name the enum Error - this is consistent with how std::io::Error, reqwest::Error and others behave.
  2. Remove the word Error from the variant names, since it's redundant
  3. Make a struct called ConditionalNoEffectError which includes named accessors for the fields
#[derive(Debug, thiserror::Error)]
/// The error type produced by [`SafetyContext`]
pub enum Error {
    #[error("extrasafe is only usable on Linux.")]
    /// Error created when trying to apply filters on non-Linux operating systems. Should never
    /// occur.
    UnsupportedOS,
    #[error(transparent)]
    /// Error created when a simple rule would override a conditional rule.
    ConditionalNoEffect(#[from] ConditionalNoEffectError),
    #[error("A libseccomp error occured. {0:?}")]
    /// An error from the underlying seccomp library.
    Seccomp(#[from] libseccomp::error::SeccompError),
}

#[derive(Debug, thiserror::Error)]
#[error("A conditional rule on syscall `{syscall}` from RuleSet `{ruleset}` would be overridden by a simple rule from RuleSet `{overridden_by}`.")]
pub struct ConditionalNoEffectError {
    syscall: syscalls::Sysno,
    ruleset: &'static str,
    overridden_by: &'static str,
}

impl ConditionalNoEffectError {
    // Should this be pub, or pub(crate)?
    pub fn new(syscall: syscalls::Sysno, ruleset: &'static str, overridden_by: &'static str) -> Self {
        Self { syscall, ruleset, overridden_by }
    }

    pub fn syscall(&self) -> syscalls::Sysno {
        self.syscall
    }
    
    pub fn ruleset(&self) -> &str {
        self.ruleset
    }
    
    pub fn overridden_by(&self) -> &str {
        self.overridden_by
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions