From bb06ad76a964862b7c3c44beb14040e842bfc493 Mon Sep 17 00:00:00 2001 From: fan-tastic-z Date: Wed, 26 Jun 2024 21:20:05 +0800 Subject: [PATCH] fix: push message mod ensure error --- src/app.rs | 13 +++++++------ src/grab/seebug.rs | 2 +- src/push/dingding.rs | 2 +- src/push/lark.rs | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/app.rs b/src/app.rs index 52d94c2..9c8b594 100644 --- a/src/app.rs +++ b/src/app.rs @@ -5,7 +5,7 @@ use snafu::ResultExt; use std::{collections::HashMap, sync::Arc, time::Duration}; use tokio::{runtime::Runtime, task::JoinSet, time}; use tokio_cron_scheduler::{Job, JobScheduler}; -use tracing::{info, warn}; +use tracing::{error, info, warn}; use crate::{ config::Config, @@ -220,17 +220,18 @@ impl WatchVulnApp { let message = msg.clone(); let title = title.clone(); set.spawn(async move { - bot_clone - .push_markdown(title, message) - .await - .expect("push markdown error") + if let Err(e) = bot_clone.push_markdown(title, message).await { + error!("push to bot error: {:?}", e); + warn!("push to bot error: {:?}", e); + return Err(format!("push to bot error:{}", e)); + } + Ok(()) }); } let mut is_push = true; while let Some(set_res) = set.join_next().await { if set_res.is_err() { is_push = false; - warn!("push message error: {:?}", set_res.err()); } } is_push diff --git a/src/grab/seebug.rs b/src/grab/seebug.rs index 4e5b435..3778088 100644 --- a/src/grab/seebug.rs +++ b/src/grab/seebug.rs @@ -81,7 +81,7 @@ impl SeeBugCrawler { let document = self.get_document(&url).await?; let selector = Selector::parse(".sebug-table tbody tr").context(SelectorSnafu)?; let tr_elements = document.select(&selector).collect::>(); - ensure!(tr_elements.is_empty(), ParseSeeBugHtmlErrSnafu,); + ensure!(!tr_elements.is_empty(), ParseSeeBugHtmlErrSnafu); let mut res = Vec::with_capacity(tr_elements.len()); for el in tr_elements { let (href, unique_key) = match self.get_href(el) { diff --git a/src/push/dingding.rs b/src/push/dingding.rs index a3087ab..df2e163 100644 --- a/src/push/dingding.rs +++ b/src/push/dingding.rs @@ -52,7 +52,7 @@ impl MessageBot for DingDing { .with_context(|_| HttpClientErrSnafu { url: DING_API_URL })?; ensure!( - res.errcode != 0, + res.errcode == 0, DingPushErrSnafu { errorcode: res.errcode } diff --git a/src/push/lark.rs b/src/push/lark.rs index 88807c8..de22670 100644 --- a/src/push/lark.rs +++ b/src/push/lark.rs @@ -39,7 +39,7 @@ impl MessageBot for Lark { .json() .await .with_context(|_| HttpClientErrSnafu { url })?; - ensure!(res.code != 0, LarkPushErrSnafu { code: res.code }); + ensure!(res.code == 0, LarkPushErrSnafu { code: res.code }); Ok(()) }