Compare commits

..

No commits in common. "b57720a2f875ea8766fbcbd555a5c31ca91c0247" and "5a65c713bd9455fc53c34e4821c6622e3d9bf87d" have entirely different histories.

2 changed files with 29 additions and 13 deletions

View File

@ -1,5 +1,6 @@
use std::{collections::HashMap, fmt, fs::File, io::BufReader};
use anyhow::Context;
use matrix_sdk::ruma::{OwnedRoomOrAliasId, OwnedUserId, RoomOrAliasId, UserId};
use serde::de;
@ -111,7 +112,7 @@ where
deserializer.deserialize_any(OptionalRoomOrAliasIdVisitor)
}
fn load_blocking(path: String) -> anyhow::Result<Config> {
fn load_blocking(path: &String) -> anyhow::Result<Config> {
let f = File::open(path)?;
let r = BufReader::new(f);
let config: Config = serde_yaml::from_reader(r)?;
@ -120,6 +121,9 @@ fn load_blocking(path: String) -> anyhow::Result<Config> {
pub async fn load<S: AsRef<str>>(path: S) -> anyhow::Result<Config> {
let p = String::from(path.as_ref());
let config = tokio::task::spawn_blocking(move || load_blocking(p)).await??;
let config = tokio::task::spawn_blocking(move || {
load_blocking(&p).with_context(|| format!("Failed to load config from {}", p))
})
.await??;
Ok(config)
}

View File

@ -8,8 +8,9 @@ extern crate serde;
mod config;
mod event;
use std::{env, net::IpAddr, ops::Deref, sync::Arc, time::Duration};
use std::{env, net::IpAddr, ops::Deref, process::exit, sync::Arc, time::Duration};
use anyhow::Context;
use constant_time_eq::constant_time_eq;
use event::{GitlabEvent, GitlabEventExt};
use http::StatusCode;
@ -49,7 +50,10 @@ async fn matrix_connect(config: &config::Config) -> anyhow::Result<Client> {
let sync_client = client.clone();
tokio::spawn(async move {
let settings = build_sync_settings(&sync_client).await;
sync_client.sync(settings).await.unwrap();
if let Err(err) = sync_client.sync(settings).await {
error!("Matrix sync failed: {}", err);
exit(1);
}
});
Ok(client)
@ -129,23 +133,18 @@ async fn handle_gitlab_event(
Ok(())
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let lenv = env_logger::Env::new()
.filter("BEBOT_LOG")
.write_style("BEBOT_LOG_STYLE");
env_logger::init_from_env(lenv);
async fn run() -> anyhow::Result<()> {
let config_path = env::args()
.nth(1)
.expect("Config file should be passed as only parameter");
.ok_or_else(|| anyhow!("Config file should be passed as only parameter"))?;
let config = Arc::new(config::load(config_path).await?);
let addr = config
.bind_address
.as_ref()
.map(|ba| ba.clone())
.unwrap_or_else(|| "127.0.0.1".to_string())
.parse::<IpAddr>()?;
.parse::<IpAddr>()
.context("Failed to parse bind_address")?;
let port = config.bind_port.unwrap_or(3000);
let matrix_client = matrix_connect(&config).await?;
@ -191,3 +190,16 @@ async fn main() -> anyhow::Result<()> {
Ok(())
}
#[tokio::main]
async fn main() {
let lenv = env_logger::Env::new()
.filter("BEBOT_LOG")
.write_style("BEBOT_LOG_STYLE");
env_logger::init_from_env(lenv);
if let Err(err) = run().await {
error!("{}", err);
exit(1);
}
}