added first version of try_audit! macro #32

Add try_audit macro
This commit is contained in:
slipperyBishop 2019-03-25 18:55:15 +10:00 committed by Firstyear
parent 3c964c51e7
commit 769bc5c17b
2 changed files with 15 additions and 7 deletions

View file

@ -52,6 +52,19 @@ macro_rules! audit_segment {
}}; }};
} }
macro_rules! try_audit {
($audit:ident, $result:expr, $logFormat:expr, $errorType:expr) => {
match $result {
Ok(v) => v,
Err(e) => {
audit_log!($audit, $logFormat, e);
return Err($errorType);
}
}
};
}
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
enum AuditEvent { enum AuditEvent {
Log(AuditLog), Log(AuditLog),

View file

@ -391,13 +391,8 @@ impl BackendWriteTransaction {
.conn .conn
.backup(rusqlite::DatabaseName::Main, dstPath, None); .backup(rusqlite::DatabaseName::Main, dstPath, None);
match result { try_audit!(audit, result, "Error in sqlite {:?}", OperationError::SQLiteError);
Ok(_) => Ok(()), Ok(())
Err(e) => {
audit_log!(audit, "Error in sqlite {:?}", e);
Err(OperationError::SQLiteError)
}
}
} }
// Should this be offline only? // Should this be offline only?