More meaningful error message when config file does not exist.

This commit is contained in:
redxef 2023-10-15 15:44:49 +02:00
parent 690777aa16
commit 4c0bcac50b
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921

View file

@ -2,7 +2,7 @@ use std::collections::HashMap;
use std::path::PathBuf; use std::path::PathBuf;
use std::str::FromStr; use std::str::FromStr;
use anyhow::Result; use anyhow::{Context, Result};
use clap::Parser; use clap::Parser;
use log::{debug, info, warn}; use log::{debug, info, warn};
use tokio::io::AsyncReadExt; use tokio::io::AsyncReadExt;
@ -167,7 +167,9 @@ async fn main() -> Result<()> {
tokio::io::stdin().read_to_string(&mut config).await?; tokio::io::stdin().read_to_string(&mut config).await?;
} else { } else {
tokio::fs::File::open(args.config.as_ref().unwrap()) tokio::fs::File::open(args.config.as_ref().unwrap())
.await? .await.with_context(
|| format!("Failed to read config file {}", args.config.as_ref().unwrap().to_string_lossy())
)?
.read_to_string(&mut config) .read_to_string(&mut config)
.await?; .await?;
} }