limit error printing
This commit is contained in:
parent
92f3c09252
commit
393db5da62
|
@ -2,6 +2,8 @@ use bip::bp;
|
|||
use std::fmt;
|
||||
use std::io::{BufRead, BufReader};
|
||||
|
||||
const ERR_MAX: usize = 40;
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
pub enum Error {
|
||||
|
@ -39,12 +41,21 @@ fn read_bip<R: BufRead>(buf: R) -> Result<Vec<bip::Node>> {
|
|||
.collect();
|
||||
|
||||
let err_count = errors.iter().fold(0, |count, err| {
|
||||
eprintln!("error: {err}");
|
||||
if count < ERR_MAX {
|
||||
eprintln!("error: {err}");
|
||||
}
|
||||
count + 1
|
||||
});
|
||||
|
||||
if err_count > 0 {
|
||||
eprintln!("{err_count} error{}", if err_count == 1 { "" } else { "s" });
|
||||
let count_fmt = format!("{err_count} error{}", if err_count == 1 { "" } else { "s" });
|
||||
|
||||
if err_count >= ERR_MAX {
|
||||
eprintln!("{} ({} shown)", count_fmt, ERR_MAX);
|
||||
} else {
|
||||
eprintln!("{}", count_fmt);
|
||||
}
|
||||
|
||||
Err(Error::ReadError)
|
||||
} else {
|
||||
bip::Parser::new(&syms).parse().map_err(Error::ParseError)
|
||||
|
|
Loading…
Reference in New Issue