on master help sign in
Add error handling for parsing errors
commit2109a7830b8f8630ead4313656b86bfd6c05bc81 authorsharkdp <davidpeter@web.de> dateWed 17 Oct 2018, 20:21 (8 years ago) parentec27c78
2 files changed+11−10
src/controller.rs+1−1 src/output.rs+10−9
src/controller.rs+1−1
@@ -19,7 +19,7 @@ impl<'b> Controller<'b> {
1919 }
2020
2121 pub fn run(&self) -> Result<bool> {
22− let mut output_type = OutputType::from_mode(self.config.paging_mode);
22+ let mut output_type = OutputType::from_mode(self.config.paging_mode)?;
2323 let writer = output_type.handle()?;
2424 let mut no_errors: bool = true;
2525
src/output.rs+10−9
@@ -15,22 +15,23 @@ pub enum OutputType {
1515}
1616
1717impl OutputType {
18− pub fn from_mode(mode: PagingMode) -> Self {
18+ pub fn from_mode(mode: PagingMode) -> Result<Self> {
1919 use self::PagingMode::*;
20− match mode {
21− Always => OutputType::try_pager(false),
22− QuitIfOneScreen => OutputType::try_pager(true),
20+ Ok(match mode {
21+ Always => OutputType::try_pager(false)?,
22+ QuitIfOneScreen => OutputType::try_pager(true)?,
2323 _ => OutputType::stdout(),
24− }
24+ })
2525 }
2626
2727 /// Try to launch the pager. Fall back to stdout in case of errors.
28− fn try_pager(quit_if_one_screen: bool) -> Self {
28+ fn try_pager(quit_if_one_screen: bool) -> Result<Self> {
2929 let pager = env::var("BAT_PAGER")
3030 .or_else(|_| env::var("PAGER"))
3131 .unwrap_or(String::from("less"));
3232
33− let pagerflags = shell_words::split(&pager).unwrap_or(vec![pager]);
33+ let pagerflags = shell_words::split(&pager)
34+ .chain_err(|| "Could not parse (BAT_)PAGER environment variable.")?;
3435
3536 let less_path = PathBuf::from(&pagerflags[0]);
3637 let is_less = less_path.file_stem() == Some(&OsString::from("less"));
@@ -49,12 +50,12 @@ impl OutputType {
4950 Command::new(&less_path)
5051 };
5152
52− process
53+ Ok(process
5354 .args(&pagerflags[1..])
5455 .stdin(Stdio::piped())
5556 .spawn()
5657 .map(OutputType::Pager)
57− .unwrap_or_else(|_| OutputType::stdout())
58+ .unwrap_or_else(|_| OutputType::stdout()))
5859 }
5960
6061 fn stdout() -> Self {