Skip to content

Commit

Permalink
update(plugin): make with_last_error() lazy
Browse files Browse the repository at this point in the history
Only get the error message from the framework if there was
an actual error

Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
  • Loading branch information
gnosek authored and poiana committed Oct 21, 2024
1 parent 8d0ae79 commit 6353e9d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 0 additions & 1 deletion falco_plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ pub mod async_event {
/// The event type that can be emitted from async event plugins
pub use falco_event::events::types::PPME_ASYNCEVENT_E as AsyncEvent;


pub use crate::plugin::async_event::async_handler::AsyncHandler;
pub use crate::plugin::async_event::AsyncEventPlugin;

Expand Down
12 changes: 7 additions & 5 deletions falco_plugin/src/plugin/error/as_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ where
type Decorated = anyhow::Result<T>;

fn with_last_error(self, last_error: &LastError) -> Self::Decorated {
let Some(msg) = last_error.get() else {
return self.map_err(|e| e.into());
};

match self {
Ok(ok) => Ok(ok),
Err(_) => self.context(msg),
Err(_) => {
let Some(msg) = last_error.get() else {
return self.map_err(|e| e.into());
};

self.context(msg)
}
}
}
}

0 comments on commit 6353e9d

Please sign in to comment.