wip: replace dyn Error with concrete

This commit is contained in:
2023-11-27 01:18:28 +11:00
parent aabf39f041
commit 6e60f58145
8 changed files with 181 additions and 93 deletions

View File

@@ -3,12 +3,14 @@ mod config;
pub(crate) mod error;
use std::env;
use std::error as std_err;
use anyhow::Context;
pub async fn start() -> Result<(), Box<dyn std_err::Error>> {
const WINGMATE_CONFIG_PATH: &'static str = "WINGMATE_CONFIG_PATH";
pub async fn start() -> Result<(), error::WingmateInitError> {
let mut vec_search: Vec<String> = Vec::new();
match env::var("WINGMATE_CONFIG_PATH") {
match env::var(WINGMATE_CONFIG_PATH) {
Ok(paths) => {
for p in paths.split(':') {
vec_search.push(String::from(p));
@@ -16,7 +18,8 @@ pub async fn start() -> Result<(), Box<dyn std_err::Error>> {
},
Err(e) => {
if let env::VarError::NotUnicode(_) = e {
return Err(e.into());
return Err(e).context(format!("reading {} env var", WINGMATE_CONFIG_PATH))
.map_err(|e| {error::WingmateInitError::Other { source: e }} );
} else {
vec_search.push(String::from("/etc/wingmate"));
}