@@ -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 {