Write attempted config file location into the log
This commit is contained in:
14
src/main.rs
14
src/main.rs
@@ -1,3 +1,4 @@
|
|||||||
|
use std::env;
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use std::{fs::File, io::BufReader};
|
use std::{fs::File, io::BufReader};
|
||||||
|
|
||||||
@@ -51,7 +52,17 @@ enum RuntimeError {
|
|||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
fn load() -> Result<Self, ConfigLoadError> {
|
fn load() -> Result<Self, ConfigLoadError> {
|
||||||
let file = File::open("config.json").map_err(ConfigLoadError::OpenFailed)?;
|
let env_var_name = "AMPLIFIER_BOT_CONFIG_FILE";
|
||||||
|
let default_filename = "./config.json";
|
||||||
|
let path = env::var(env_var_name).unwrap_or_else(|_err| {
|
||||||
|
warn!(
|
||||||
|
"Cannot read env var '{}', assuming '{}'",
|
||||||
|
env_var_name, default_filename
|
||||||
|
);
|
||||||
|
default_filename.to_owned()
|
||||||
|
});
|
||||||
|
info!("Reading configuration from {}", path);
|
||||||
|
let file = File::open(path).map_err(ConfigLoadError::OpenFailed)?;
|
||||||
let reader = BufReader::new(file);
|
let reader = BufReader::new(file);
|
||||||
serde_json::from_reader(reader).map_err(ConfigLoadError::ReadError)
|
serde_json::from_reader(reader).map_err(ConfigLoadError::ReadError)
|
||||||
}
|
}
|
||||||
@@ -62,7 +73,6 @@ async fn main() -> Result<(), UnresolvableError> {
|
|||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
info!("Starting amplifier-bot");
|
info!("Starting amplifier-bot");
|
||||||
|
|
||||||
info!("Reading configuration");
|
|
||||||
let config = Config::load().map_err(UnresolvableError::ConfigLoadError)?;
|
let config = Config::load().map_err(UnresolvableError::ConfigLoadError)?;
|
||||||
|
|
||||||
info!("Long-polling for updates...");
|
info!("Long-polling for updates...");
|
||||||
|
|||||||
Reference in New Issue
Block a user