diff --git a/bipc/src/lib.rs b/bipc/src/lib.rs index 9d118ef..a4728c4 100644 --- a/bipc/src/lib.rs +++ b/bipc/src/lib.rs @@ -2,6 +2,8 @@ use bip::bp; use std::fmt; use std::io::{BufRead, BufReader}; +const ERR_MAX: usize = 40; + pub type Result = std::result::Result; pub enum Error { @@ -39,12 +41,21 @@ fn read_bip(buf: R) -> Result> { .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)