falco_plugin/plugin/error/
mod.rs

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