Skip to content

Commit

Permalink
feat: handles message parsing error & prints an error log (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
bilthon committed Jun 10, 2024
1 parent bb9c57c commit 6f54ceb
Showing 1 changed file with 104 additions and 100 deletions.
204 changes: 104 additions & 100 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use sqlx::{Pool, Sqlite};
use std::sync::Arc;
use tokio::sync::Mutex;
use tracing::info;
use tracing::error;

fn warning_msg(action: &Action, e: anyhow::Error) {
tracing::warn!("Error in {} with context {}", action, e);
Expand Down Expand Up @@ -62,123 +63,126 @@ pub async fn run(

if let Ok(m) = message {
let message = Message::from_json(&m);
if let Ok(msg) = message {
if msg.get_inner_message_kind().verify() {
if let Some(action) = msg.inner_action() {
match action {
Action::NewOrder => {
if let Err(e) =
order_action(msg, &event, &my_keys, &pool).await
{
warning_msg(&action, e)
match message {
Ok(msg) => {
if msg.get_inner_message_kind().verify() {
if let Some(action) = msg.inner_action() {
match action {
Action::NewOrder => {
if let Err(e) =
order_action(msg, &event, &my_keys, &pool).await
{
warning_msg(&action, e)
}
}
}
Action::TakeSell => {
if let Err(e) =
take_sell_action(msg, &event, &my_keys, &pool).await
{
warning_msg(&action, e)
Action::TakeSell => {
if let Err(e) =
take_sell_action(msg, &event, &my_keys, &pool).await
{
warning_msg(&action, e)
}
}
}
Action::TakeBuy => {
if let Err(e) =
take_buy_action(msg, &event, &my_keys, &pool).await
{
warning_msg(&action, e)
Action::TakeBuy => {
if let Err(e) =
take_buy_action(msg, &event, &my_keys, &pool).await
{
warning_msg(&action, e)
}
}
}
Action::FiatSent => {
if let Err(e) =
fiat_sent_action(msg, &event, &my_keys, &pool).await
{
warning_msg(&action, e)
Action::FiatSent => {
if let Err(e) =
fiat_sent_action(msg, &event, &my_keys, &pool).await
{
warning_msg(&action, e)
}
}
}
Action::Release => {
if let Err(e) = release_action(
msg, &event, &my_keys, &pool, ln_client,
)
.await
{
warning_msg(&action, e)
Action::Release => {
if let Err(e) = release_action(
msg, &event, &my_keys, &pool, ln_client,
)
.await
{
warning_msg(&action, e)
}
}
}
Action::Cancel => {
if let Err(e) = cancel_action(
msg, &event, &my_keys, &pool, ln_client,
)
.await
{
warning_msg(&action, e)
Action::Cancel => {
if let Err(e) = cancel_action(
msg, &event, &my_keys, &pool, ln_client,
)
.await
{
warning_msg(&action, e)
}
}
}
Action::AddInvoice => {
if let Err(e) =
add_invoice_action(msg, &event, &my_keys, &pool)
.await
{
warning_msg(&action, e)
Action::AddInvoice => {
if let Err(e) =
add_invoice_action(msg, &event, &my_keys, &pool)
.await
{
warning_msg(&action, e)
}
}
}
Action::PayInvoice => todo!(),
Action::RateUser => {
if let Err(e) = update_user_reputation_action(
msg,
&event,
&my_keys,
&pool,
rate_list.clone(),
)
.await
{
warning_msg(&action, e)
Action::PayInvoice => todo!(),
Action::RateUser => {
if let Err(e) = update_user_reputation_action(
msg,
&event,
&my_keys,
&pool,
rate_list.clone(),
)
.await
{
warning_msg(&action, e)
}
}
}
Action::Dispute => {
if let Err(e) =
dispute_action(msg, &event, &my_keys, &pool).await
{
warning_msg(&action, e)
Action::Dispute => {
if let Err(e) =
dispute_action(msg, &event, &my_keys, &pool).await
{
warning_msg(&action, e)
}
}
}
Action::AdminCancel => {
if let Err(e) = admin_cancel_action(
msg, &event, &my_keys, &pool, ln_client,
)
.await
{
warning_msg(&action, e)
Action::AdminCancel => {
if let Err(e) = admin_cancel_action(
msg, &event, &my_keys, &pool, ln_client,
)
.await
{
warning_msg(&action, e)
}
}
}
Action::AdminSettle => {
if let Err(e) = admin_settle_action(
msg, &event, &my_keys, &pool, ln_client,
)
.await
{
warning_msg(&action, e)
Action::AdminSettle => {
if let Err(e) = admin_settle_action(
msg, &event, &my_keys, &pool, ln_client,
)
.await
{
warning_msg(&action, e)
}
}
}
Action::AdminAddSolver => {
if let Err(e) = admin_add_solver_action(
msg, &event, &my_keys, &pool,
)
.await
{
warning_msg(&action, e)
Action::AdminAddSolver => {
if let Err(e) = admin_add_solver_action(
msg, &event, &my_keys, &pool,
)
.await
{
warning_msg(&action, e)
}
}
}
Action::AdminTakeDispute => {
if let Err(e) =
admin_take_dispute_action(msg, &event, &pool).await
{
warning_msg(&action, e)
Action::AdminTakeDispute => {
if let Err(e) =
admin_take_dispute_action(msg, &event, &pool).await
{
warning_msg(&action, e)
}
}
_ => info!("Received message with action {:?}", action),
}
_ => info!("Received message with action {:?}", action),
}
}
}
Err(e) => error!("Failed to parse message from JSON: {:?}", e),
}
};
}
Expand Down

0 comments on commit 6f54ceb

Please sign in to comment.