From 393db5da62dcabdf9e9913fbe154dc14018e3229 Mon Sep 17 00:00:00 2001 From: mos Date: Fri, 1 Nov 2024 10:48:01 +0100 Subject: [PATCH] limit error printing --- bipc/src/lib.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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)