Skip to main content

falco_plugin/error/
mod.rs

1pub mod as_result;
2pub mod ffi_result;
3pub mod last_error;
4pub mod panic;
5
6use thiserror::Error;
7
8use falco_plugin_api::ss_plugin_rc;
9/// # Failure reason to report to the plugin framework
10#[derive(Debug, Clone, Copy, Error)]
11pub enum FailureReason {
12    /// # General failure
13    ///
14    /// This failure reason indicates an actual error that occurred and may end up with
15    /// the Falco process shutting down (after a long chain of error propagation).
16    ///
17    /// All [`Result`] values without a specific reason set default to this value
18    #[error("failure")]
19    Failure,
20
21    /// # Timeout
22    ///
23    /// This is not an actual failure but an indication that there's no data available yet.
24    /// This code is meaningful in source plugins, in the [`next_batch`](`crate::source::SourcePluginInstance::next_batch`)
25    /// method.
26    ///
27    /// The framework will retry the call at a later time.
28    #[error("timeout")]
29    Timeout,
30
31    /// # End of data
32    ///
33    /// This is not an actual failure but an indication that there will be no more data.
34    /// This code is meaningful in source plugins, in the [`next_batch`](`crate::source::SourcePluginInstance::next_batch`)
35    /// method.
36    ///
37    /// The framework will stop the event collection process cleanly.
38    #[error("end of data")]
39    Eof,
40
41    /// # Not supported
42    ///
43    /// This code indicates that an operation is not supported.
44    #[error("not supported")]
45    NotSupported,
46}
47
48impl From<FailureReason> for ss_plugin_rc {
49    fn from(value: FailureReason) -> Self {
50        match value {
51            FailureReason::Failure => falco_plugin_api::ss_plugin_rc_SS_PLUGIN_FAILURE,
52            FailureReason::Timeout => falco_plugin_api::ss_plugin_rc_SS_PLUGIN_TIMEOUT,
53            FailureReason::Eof => falco_plugin_api::ss_plugin_rc_SS_PLUGIN_EOF,
54            FailureReason::NotSupported => falco_plugin_api::ss_plugin_rc_SS_PLUGIN_NOT_SUPPORTED,
55        }
56    }
57}