From 801622ecf2fc388de746820320b458e9403a8530 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 20 Jun 2017 19:12:14 +0200 Subject: [PATCH 1/3] Add output where paths is set --- libimagrt/src/runtime.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libimagrt/src/runtime.rs b/libimagrt/src/runtime.rs index f8f29a2d..e4597c73 100644 --- a/libimagrt/src/runtime.rs +++ b/libimagrt/src/runtime.rs @@ -103,6 +103,10 @@ impl<'a> Runtime<'a> { let configpath = matches.value_of("config") .map_or_else(|| rtp.clone(), PathBuf::from); + debug!("RTP path = {:?}", rtp); + debug!("Store path = {:?}", storepath); + debug!("Config path = {:?}", configpath); + let cfg = match Configuration::new(&configpath) { Err(e) => if e.err_type() != ConfigErrorKind::NoConfigFileFound { return Err(RuntimeErrorKind::Instantiate.into_error_with_cause(Box::new(e))); From 2790042f6f7b439c1287abc88ac86bf3088e9bbb Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 20 Jun 2017 20:13:36 +0200 Subject: [PATCH 2/3] Propagate parsing errors This somehow resolved another error as well, where the toml parser reported an error for the parsed file, despite beeing one in the file. I don't know how this commit fixed this, but it scares the shit out of me. --- libimagrt/src/configuration.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/libimagrt/src/configuration.rs b/libimagrt/src/configuration.rs index e6c6c726..dc19dca4 100644 --- a/libimagrt/src/configuration.rs +++ b/libimagrt/src/configuration.rs @@ -23,6 +23,9 @@ use std::ops::Deref; use toml::Value; +use error::RuntimeErrorKind as REK; +use libimagerror::into::IntoError; + generate_error_module!( generate_error_types!(ConfigError, ConfigErrorKind, TOMLParserError => "TOML Parsing error", @@ -221,14 +224,12 @@ fn fetch_config(rtp: &PathBuf) -> Result { use std::env; use std::fs::File; use std::io::Read; - use std::io::Write; - use std::io::stderr; use xdg_basedir; use itertools::Itertools; use libimagutil::variants::generate_variants as gen_vars; - use libimagerror::trace::trace_error; + use self::error::MapErrInto; let variants = vec!["config", "config.toml", "imagrc", "imagrc.toml"]; let modifier = |base: &PathBuf, v: &'static str| { @@ -250,6 +251,7 @@ fn fetch_config(rtp: &PathBuf) -> Result { .flatten() .filter(|path| path.exists() && path.is_file()) .map(|path| { + debug!("Reading {:?}", path); let content = { let mut s = String::new(); let f = File::open(path); @@ -261,17 +263,18 @@ fn fetch_config(rtp: &PathBuf) -> Result { s }; - match ::toml::de::from_str(&content[..]) { - Ok(res) => res, - Err(e) => { - write!(stderr(), "Config file parser error:").ok(); - trace_error(&e); - None - } - } + trace!("Contents of config file: \n---\n{}\n---", content); + + let toml = ::toml::de::from_str(&content[..]) + .map_err_into(ConfigErrorKind::TOMLParserError) + .map_err(Box::new) + .map_err(|e| REK::Instantiate.into_error_with_cause(e)); + + Some(toml) }) - .filter(|loaded| loaded.is_some()) - .nth(0) + .filter_map(|x| x) + .filter(|loaded| loaded.is_ok()) .map(|inner| Value::Table(inner.unwrap())) + .nth(0) .ok_or(ConfigErrorKind::NoConfigFileFound.into()) } From 699f4083e9eb84a691bdbb0167178a5268ba5e53 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 20 Jun 2017 20:57:03 +0200 Subject: [PATCH 3/3] Add Runtime::store_backend_to_stdout(), make _stdio() variant use stdin properly --- libimagrt/src/runtime.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/libimagrt/src/runtime.rs b/libimagrt/src/runtime.rs index e4597c73..60ec08f3 100644 --- a/libimagrt/src/runtime.rs +++ b/libimagrt/src/runtime.rs @@ -358,7 +358,7 @@ impl<'a> Runtime<'a> { use std::rc::Rc; use std::cell::RefCell; - let mut input = ::std::io::empty(); + let mut input = ::std::io::stdin(); let output = ::std::io::stdout(); let output = Rc::new(RefCell::new(output)); let mapper = JsonMapper::new(); @@ -372,6 +372,25 @@ impl<'a> Runtime<'a> { }) } + pub fn store_backend_to_stdout(&mut self) -> Result<(), RuntimeError> { + use libimagstore::file_abstraction::stdio::mapper::json::JsonMapper; + use libimagstore::file_abstraction::stdio::out::StdoutFileAbstraction; + use std::rc::Rc; + use std::cell::RefCell; + + let output = ::std::io::stdout(); + let output = Rc::new(RefCell::new(output)); + let mapper = JsonMapper::new(); + + StdoutFileAbstraction::new(output, mapper) + .map_err_into(RuntimeErrorKind::Instantiate) + .and_then(|backend| { + self.store + .reset_backend(Box::new(backend)) + .map_err_into(RuntimeErrorKind::Instantiate) + }) + } + /// Get a editor command object which can be called to open the $EDITOR pub fn editor(&self) -> Option { self.cli()