Change config format from yaml to toml

This commit is contained in:
2025-11-16 10:33:14 +01:00
parent 39c7208b44
commit 50afa9f7fb
5 changed files with 111 additions and 66 deletions

View File

@@ -2,8 +2,8 @@ use thiserror::Error;
#[derive(Error, Debug)]
pub enum ConfigLoadError {
#[error("Failed to open config file: {0}")]
OpenFailed(#[source] std::io::Error),
#[error("Failed to read config file: {0}")]
ReadError(#[source] serde_yaml::Error),
ReadError(#[source] std::io::Error),
#[error("Failed to parse config file: {0}")]
ParseError(#[source] toml::de::Error),
}

View File

@@ -6,7 +6,8 @@ mod migrating_send;
mod schema;
use std::env::args;
use std::{env, fs::File, io::BufReader, sync::Arc};
use std::fs::read_to_string;
use std::{env, sync::Arc};
use anyhow::Result;
use async_mutex::Mutex;
@@ -48,7 +49,7 @@ pub struct Config {
impl Config {
fn load() -> Result<Self, ConfigLoadError> {
let env_var_name = "CALENDAR_BOT_CONFIG_FILE";
let default_filename = "./config.yaml";
let default_filename = "./config.toml";
let path = env::var(env_var_name).unwrap_or_else(|_| {
warn!(
"Cannot read env var '{}', assuming '{}'",
@@ -57,9 +58,8 @@ impl Config {
default_filename.to_owned()
});
info!("Reading configuration from {}", path);
let file = File::open(path).map_err(ConfigLoadError::OpenFailed)?;
let reader = BufReader::new(file);
serde_yaml::from_reader(reader).map_err(ConfigLoadError::ReadError)
let s = read_to_string(path).map_err(ConfigLoadError::ReadError)?;
toml::from_str(&s).map_err(ConfigLoadError::ParseError)
}
}