diff options
Diffstat (limited to 'bin/domain/imag-contact/src/create.rs')
-rw-r--r-- | bin/domain/imag-contact/src/create.rs | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/bin/domain/imag-contact/src/create.rs b/bin/domain/imag-contact/src/create.rs index 22394f7a..3c8b3f07 100644 --- a/bin/domain/imag-contact/src/create.rs +++ b/bin/domain/imag-contact/src/create.rs @@ -45,10 +45,10 @@ use toml_query::read::TomlValueReadExt; use toml_query::read::Partial; use toml::Value; use uuid::Uuid; -use failure::Error; -use failure::err_msg; -use failure::Fallible as Result; -use failure::ResultExt; +use anyhow::Error; + +use anyhow::Result; +use anyhow::Context; use libimagcontact::store::ContactStore; use libimagrt::runtime::Runtime; @@ -85,15 +85,15 @@ pub fn create(rt: &Runtime) -> Result<()> { let collection_name = String::from(collection_name); let ref_config = rt // TODO: Re-Deserialize to libimagentryref::reference::Config .config() - .ok_or_else(|| err_msg("Configuration missing, cannot continue!"))? + .ok_or_else(|| anyhow!("Configuration missing, cannot continue!"))? .read_partial::<libimagentryref::reference::Config>()? - .ok_or_else(|| format_err!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?; + .ok_or_else(|| anyhow!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?; // TODO: Refactor the above to libimagutil or libimagrt? let (mut dest, location, uuid) : (Box<dyn Write>, Option<PathBuf>, String) = { if let Some(mut fl) = scmd.value_of("file-location").map(PathBuf::from) { let uuid = if fl.is_file() { - return Err(err_msg("File does exist, cannot create/override")) + return Err(anyhow!("File does exist, cannot create/override")) } else if fl.is_dir() { let uuid = Uuid::new_v4().to_hyphenated().to_string(); fl.push(uuid.clone()); @@ -135,7 +135,7 @@ pub fn create(rt: &Runtime) -> Result<()> { None => fl.file_name() .and_then(|fname| fname.to_str()) .map(String::from) - .ok_or_else(|| err_msg("Cannot calculate UUID for vcard"))?, + .ok_or_else(|| anyhow!("Cannot calculate UUID for vcard"))?, }; (Box::new(file), Some(fl), uuid_string) @@ -147,7 +147,7 @@ pub fn create(rt: &Runtime) -> Result<()> { }; let mut input = rt.stdin().ok_or_else(|| { - err_msg("No input stream. Cannot ask for permission") + anyhow!("No input stream. Cannot ask for permission") })?; let mut output = rt.stdout(); @@ -156,7 +156,7 @@ pub fn create(rt: &Runtime) -> Result<()> { ::libimagentryedit::edit::edit_in_tmpfile(&rt, &mut template)?; if template == TEMPLATE || template.is_empty() { - return Err(err_msg("No (changed) content in tempfile. Not doing anything.")) + return Err(anyhow!("No (changed) content in tempfile. Not doing anything.")) } match ::toml::de::from_str(&template) @@ -265,7 +265,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Key 'nickname.[{}].name' missing", i)) + return Err(anyhow!("Key 'nickname.[{}].name' missing", i)) } }, }; @@ -286,7 +286,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Type Error: Expected Array or String at 'nickname'")) + return Err(anyhow!("Type Error: Expected Array or String at 'nickname'")) } }, None => { @@ -326,7 +326,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Key 'phones.[{}].type' missing", i)) + return Err(anyhow!("Key 'phones.[{}].type' missing", i)) } } }; @@ -338,7 +338,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Key 'phones.[{}].number' missing", i)) + return Err(anyhow!("Key 'phones.[{}].number' missing", i)) } } }; @@ -355,7 +355,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Expected Array at 'phones'.")) + return Err(anyhow!("Expected Array at 'phones'.")) } }, None => { @@ -375,7 +375,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Key 'adresses.[{}].type' missing", i)) + return Err(anyhow!("Key 'adresses.[{}].type' missing", i)) } }, Some(p) => p, @@ -410,7 +410,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Type Error: Expected Array at 'addresses'")) + return Err(anyhow!("Type Error: Expected Array at 'addresses'")) } }, None => { @@ -430,7 +430,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Error: 'email.[{}].type' missing", i)) + return Err(anyhow!("Error: 'email.[{}].type' missing", i)) } }, Some(p) => p, @@ -442,7 +442,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Error: 'email.[{}].addr' missing", i)) + return Err(anyhow!("Error: 'email.[{}].addr' missing", i)) } }, Some(p) => p, @@ -460,7 +460,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Type Error: Expected Array at 'email'")) + return Err(anyhow!("Type Error: Expected Array at 'email'")) } }, None => { @@ -505,7 +505,7 @@ fn read_strary_from_toml(toml: &Value, path: &'static str) -> Result<Option<Vec< match *elem { Value::String(ref s) => v.push(s.clone()), _ => { - return Err(format_err!("Type Error: '{}' must be Array<String>", path)) + return Err(anyhow!("Type Error: '{}' must be Array<String>", path)) }, } } @@ -516,7 +516,7 @@ fn read_strary_from_toml(toml: &Value, path: &'static str) -> Result<Option<Vec< warn!("Having String, wanting Array<String> ... going to auto-fix"); Ok(Some(vec![s.clone()])) }, - Ok(Some(_)) => Err(format_err!("Type Error: '{}' must be Array<String>", path)), + Ok(Some(_)) => Err(anyhow!("Type Error: '{}' must be Array<String>", path)), Ok(None) => Ok(None), Err(_) => Ok(None), } @@ -526,11 +526,11 @@ fn read_str_from_toml(toml: &Value, path: &'static str, must_be_there: bool) -> match toml.read(path)? { Some(&Value::String(ref s)) => Ok(Some(s.clone())), Some(_) => { - Err(format_err!("Type Error: '{}' must be String", path)) + Err(anyhow!("Type Error: '{}' must be String", path)) }, None => { if must_be_there { - return Err(format_err!("Expected '{}' to be present, but is not.", path)) + return Err(anyhow!("Expected '{}' to be present, but is not.", path)) } Ok(None) }, |