summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-07-25 19:52:49 +0200
committerMatthias Beyer <mail@beyermatthias.de>2019-07-25 19:52:49 +0200
commit9c896eb98b6aa77f4b4aeed84cd2a82a270e44b3 (patch)
tree6ba4188d098b0de8d91dd6159f61c1a498133240
parent5f10ab976fcc75683985d2551ff16f7858cac49a (diff)
Add checks whether variables are valid unicode and propagate appropriate error
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--lib/core/libimagrt/src/runtime.rs21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/core/libimagrt/src/runtime.rs b/lib/core/libimagrt/src/runtime.rs
index 43fa1eaf..ac3a233f 100644
--- a/lib/core/libimagrt/src/runtime.rs
+++ b/lib/core/libimagrt/src/runtime.rs
@@ -648,17 +648,26 @@ pub fn get_rtp_match<'a>(matches: &ArgMatches<'a>) -> Result<PathBuf> {
return Ok(p)
}
- if let Ok(home) = env::var("IMAG_RTP") {
- return Ok(PathBuf::from(home))
+ match env::var("IMAG_RTP").map(PathBuf::from) {
+ 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")
.map(PathBuf::from)
.map(|mut p| { p.push(".imag"); p })
- .map_err(|_| {
- 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 \
- accommodation anyways.")
+ .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 \
+ software. We are sorry for you and hope you have some \
+ accommodation anyways.")
+ }
})
}