Add checks whether variables are valid unicode and propagate appropriate error
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
5f10ab976f
commit
9c896eb98b
1 changed files with 15 additions and 6 deletions
|
@ -648,17 +648,26 @@ pub fn get_rtp_match<'a>(matches: &ArgMatches<'a>) -> Result<PathBuf> {
|
||||||
return Ok(p)
|
return Ok(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(home) = env::var("IMAG_RTP") {
|
match env::var("IMAG_RTP").map(PathBuf::from) {
|
||||||
return Ok(PathBuf::from(home))
|
Ok(p) => return Ok(p),
|
||||||
|
Err(env::VarError::NotUnicode(_)) => {
|
||||||
|
return Err(err_msg("Environment variable 'IMAG_RTP' does not contain valid Unicode"))
|
||||||
|
},
|
||||||
|
Err(env::VarError::NotPresent) => { /* passthrough */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
env::var("HOME")
|
env::var("HOME")
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.map(|mut p| { p.push(".imag"); p })
|
.map(|mut p| { p.push(".imag"); p })
|
||||||
.map_err(|_| {
|
.map_err(|e| match e {
|
||||||
|
env::VarError::NotUnicode(_) => {
|
||||||
|
err_msg("Environment variable 'HOME' does not contain valid Unicode")
|
||||||
|
},
|
||||||
|
env::VarError::NotPresent => {
|
||||||
err_msg("You seem to be $HOME-less. Please get a $HOME before using this \
|
err_msg("You seem to be $HOME-less. Please get a $HOME before using this \
|
||||||
software. We are sorry for you and hope you have some \
|
software. We are sorry for you and hope you have some \
|
||||||
accommodation anyways.")
|
accommodation anyways.")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue