Skip to content

Commit

Permalink
fix: push message mod ensure error
Browse files Browse the repository at this point in the history
  • Loading branch information
fan-tastic-z committed Jun 26, 2024
1 parent 0cfdb07 commit bb06ad7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
13 changes: 7 additions & 6 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/grab/seebug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
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) {
Expand Down
2 changes: 1 addition & 1 deletion src/push/dingding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/push/lark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down

0 comments on commit bb06ad7

Please sign in to comment.