Fix broken pipe errors

This commit is contained in:
Matthias Beyer 2018-02-14 18:38:43 +01:00
parent 876c1cb9af
commit 23e0f720e5

View file

@ -42,6 +42,7 @@ extern crate libimagbookmark;
extern crate libimagerror; extern crate libimagerror;
extern crate libimagutil; extern crate libimagutil;
use std::io::Write;
use std::process::exit; use std::process::exit;
use toml_query::read::TomlValueReadTypeExt; use toml_query::read::TomlValueReadTypeExt;
@ -53,6 +54,8 @@ use libimagbookmark::collection::BookmarkCollectionStore;
use libimagbookmark::error::BookmarkError as BE; use libimagbookmark::error::BookmarkError as BE;
use libimagbookmark::link::Link as BookmarkLink; use libimagbookmark::link::Link as BookmarkLink;
use libimagerror::trace::{MapErrTrace, trace_error}; use libimagerror::trace::{MapErrTrace, trace_error};
use libimagerror::io::ToExitCode;
use libimagerror::exit::ExitUnwrap;
mod ui; mod ui;
@ -132,10 +135,11 @@ fn list(rt: &Runtime) {
.map_err_trace_exit_unwrap(1); .map_err_trace_exit_unwrap(1);
let links = collection.links(rt.store()).map_err_trace_exit_unwrap(1); let links = collection.links(rt.store()).map_err_trace_exit_unwrap(1);
let mut out = ::std::io::stdout();
debug!("Listing..."); debug!("Listing...");
for (i, link) in links.enumerate() { for (i, link) in links.enumerate() {
match link { match link {
Ok(link) => println!("{: >3}: {}", i, link), Ok(link) => writeln!(out, "{: >3}: {}", i, link).to_exit_code().unwrap_or_exit(),
Err(e) => trace_error(&e) Err(e) => trace_error(&e)
} }
}; };