Skip to content

Commit

Permalink
Merge pull request #938 from NordSecurity/matislovas/bump_moose_14_1_0
Browse files Browse the repository at this point in the history
Bump moose 14.1.1
  • Loading branch information
matislovas authored Nov 12, 2024
2 parents f4920a9 + 69933c1 commit 5244538
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 15 deletions.
Empty file added .unreleased/bump_moose_14_1_0
Empty file.
2 changes: 1 addition & 1 deletion ci/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import os

LIBTELIO_ENV_MOOSE_RELEASE_TAG = "v13.0.1-libtelioApp"
LIBTELIO_ENV_MOOSE_RELEASE_TAG = "v14.1.1-libtelioApp"
LIBTELIO_ENV_NAT_LAB_DEPS_TAG = "v0.0.30"
LIBTELIO_ENV_ANDROID_BUILDER_TAG = "v0.0.2"
LIBTELIO_ENV_LINUX_BUILDER_TAG = "v0.0.4"
Expand Down
37 changes: 33 additions & 4 deletions crates/telio-lana/src/event_log_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ pub mod moose {
NotInitiatedError,
#[error("Failed to log event")]
EventLogError,
#[error("Internal error: {0}")]
Internal(String),
}

#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -148,11 +150,38 @@ pub mod moose {
}

pub trait InitCallback: Send {
fn after_init(&self, result: &std::result::Result<TrackerState, MooseError>);
fn after_init(&self, result: std::result::Result<TrackerState, InitError>);
}

pub trait ErrorCallback {
fn on_error(&self, error_level: MooseErrorLevel, error_code: MooseError, msg: &str);
fn on_error(
&self,
error: MooseError,
error_level: MooseErrorLevel,
error_code: i32,
msg: &str,
);
}

#[derive(Clone, Debug)]
pub struct MooseSQLiteError {
pub error_code: i32,
pub message: Option<String>,
}

#[derive(Clone, Debug)]
pub enum InitError {
SQLiteError(MooseSQLiteError),
Internal(String),
}

impl From<InitError> for Error {
fn from(moose_error: InitError) -> Error {
match moose_error {
InitError::Internal(e) => Error::Internal(e),
_ => Error::EventLogError,
}
}
}

/// Initialize logger file with current date and time.
Expand All @@ -174,10 +203,10 @@ pub mod moose {
Some(vec![event_path.as_str(), prod.to_string().as_str()]),
) {
Ok(_) => Ok(TrackerState::Ready),
_ => Err(MooseError::NotInitiated),
_ => Err(InitError::Internal("Not initialized".to_string())),
};

init_cb.after_init(&result);
init_cb.after_init(result.clone());

match result {
Ok(r) => Ok(Result::from(r)),
Expand Down
10 changes: 5 additions & 5 deletions crates/telio-lana/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ mod test {

pub struct MooseStub {
return_success: bool,
init_cb_result: Result<moose::TrackerState, moose::MooseError>,
init_cb_result: Result<moose::TrackerState, moose::InitError>,
should_call_init_cb: Option<Arc<Barrier>>,
init_cb_thread: Option<JoinHandle<()>>,
}

impl MooseStub {
fn new(
return_success: bool,
init_cb_result: Result<moose::TrackerState, moose::MooseError>,
init_cb_result: Result<moose::TrackerState, moose::InitError>,
should_call_init_cb: Option<Arc<Barrier>>,
) -> Self {
Self {
Expand All @@ -222,7 +222,7 @@ mod test {
self.init_cb_thread = Some(std::thread::spawn(move || {
if let Some(barrier) = should_call_init_cb {
barrier.wait();
init_cb.after_init(&init_cb_result);
init_cb.after_init(init_cb_result);
}
}));
if self.return_success {
Expand Down Expand Up @@ -308,7 +308,7 @@ mod test {
fn test_init_lana_with_failing_moose_init() {
let _wrapper = MooseStubWrapper::new(MooseStub::new(
false,
Err(moose::MooseError::StorageEngine),
Err(moose::InitError::Internal("Not initialized".to_string())),
Some(Arc::new(Barrier::new(1))),
));

Expand All @@ -329,7 +329,7 @@ mod test {
let init_cb_barrier = Arc::new(Barrier::new(2));
let _wrapper = MooseStubWrapper::new(MooseStub::new(
true,
Err(moose::MooseError::NotInitiated),
Err(moose::InitError::Internal("Not initialized".to_string())),
Some(init_cb_barrier.clone()),
));

Expand Down
26 changes: 21 additions & 5 deletions crates/telio-lana/src/moose_callbacks.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub use crate::event_log::moose::{
ErrorCallback, InitCallback, MooseError, MooseErrorLevel, TrackerState,
ErrorCallback, InitCallback, InitError, MooseError, MooseErrorLevel, TrackerState,
};
use crate::{DEFAULT_ORDERING, MOOSE_INITIALIZED};

Expand All @@ -12,7 +12,7 @@ pub struct MooseInitCallback;
pub struct MooseErrorCallback;

impl InitCallback for MooseInitCallback {
fn after_init(&self, result_code: &Result<TrackerState, MooseError>) {
fn after_init(&self, result_code: Result<TrackerState, InitError>) {
match result_code {
Ok(res) => {
telio_log_info!("[Moose] Init callback success: {:?}", res);
Expand All @@ -29,13 +29,29 @@ impl InitCallback for MooseInitCallback {
}

impl ErrorCallback for MooseErrorCallback {
fn on_error(&self, error_level: MooseErrorLevel, error_code: MooseError, msg: &str) {
fn on_error(
&self,
error: MooseError,
error_level: MooseErrorLevel,
error_code: i32,
msg: &str,
) {
match error_level {
MooseErrorLevel::Warning => {
telio_log_warn!("[Moose] Error callback {:?}: {:?}", error_code, msg)
telio_log_warn!(
"[Moose] Error callback {:?}, code: {:?}, msg: {:?}",
error,
error_code,
msg
)
}
MooseErrorLevel::Error => {
telio_log_warn!("[Moose] Error callback {:?}: {:?}", error_code, msg)
telio_log_error!(
"[Moose] Error callback {:?}, code: {:?}, msg: {:?}",
error,
error_code,
msg
)
}
}
}
Expand Down

0 comments on commit 5244538

Please sign in to comment.