handle ProgressStyle's template now returning a Result
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
ci/woodpecker/pull_request_closed/woodpecker Pipeline was successful

This commit is contained in:
Paul Campbell 2024-03-27 10:47:49 +00:00
parent 81e8a62555
commit 7233477c76
4 changed files with 30 additions and 5 deletions

View file

@ -30,7 +30,11 @@ pub fn generate_epubs(
let enabled_bar = ProgressBar::new(articles.len() as u64);
let style = ProgressStyle::default_bar().template(
"{spinner:.cyan} [{elapsed_precise}] {bar:40.white} {:>8} epub {pos}/{len:7} {msg:.green}",
);
).map_err(|e| {
let mut paperoni_err: PaperoniError = e.into();
paperoni_err.set_article_source("progress bar");
vec![paperoni_err]
})?;
enabled_bar.set_style(style);
if !articles.is_empty() {
enabled_bar.set_message("Generating epubs");

View file

@ -15,6 +15,8 @@ pub enum ErrorKind {
UTF8Error(String),
#[error("[ReadabilityError]: {0}")]
ReadabilityError(String),
#[error("[TemplateError]: {0}")]
TemplateError(String),
}
#[derive(Error, Debug)]
@ -128,6 +130,12 @@ impl From<std::str::Utf8Error> for PaperoniError {
}
}
impl From<indicatif::style::TemplateError> for PaperoniError {
fn from(err: indicatif::style::TemplateError) -> Self {
PaperoniError::with_kind(ErrorKind::TemplateError(err.to_string()))
}
}
#[derive(Debug, Error)]
pub enum LogError {
#[error(transparent)]

View file

@ -44,7 +44,11 @@ pub fn generate_html_exports(
let enabled_bar = ProgressBar::new(articles.len() as u64);
let style = ProgressStyle::default_bar().template(
"{spinner:.cyan} [{elapsed_precise}] {bar:40.white} {:>8} html {pos}/{len:7} {msg:.green}",
);
).map_err(|e| {
let mut paperoni_err: PaperoniError = e.into();
paperoni_err.set_article_source("progress bar");
vec![paperoni_err]
})?;
enabled_bar.set_style(style);
if !articles.is_empty() {
enabled_bar.set_message("Generating html files");

View file

@ -2,6 +2,7 @@
extern crate lazy_static;
use std::process::exit;
use std::time::Duration;
use colored::Colorize;
use comfy_table::presets::{UTF8_FULL, UTF8_HORIZONTAL_ONLY};
@ -25,6 +26,8 @@ use epub::generate_epubs;
use html::generate_html_exports;
use logs::display_summary;
use crate::errors::PaperoniError;
fn main() {
let app_config = match cli::AppConfig::init_with_cli() {
Ok(app_config) => app_config,
@ -58,9 +61,15 @@ fn run(app_config: AppConfig) {
let enabled_bar = ProgressBar::new(app_config.urls.len() as u64);
let style = ProgressStyle::default_bar().template(
"{spinner:.cyan} [{elapsed_precise}] {bar:40.white} {:>8} link {pos}/{len:7} {msg:.yellow/white}",
);
enabled_bar.set_style(style);
enabled_bar.enable_steady_tick(500);
).map_err(|e| {
let mut paperoni_err: PaperoniError = e.into();
paperoni_err.set_article_source("progress bar");
vec![paperoni_err]
});
if let Ok(style) = style {
enabled_bar.set_style(style);
}
enabled_bar.enable_steady_tick(Duration::from_millis(500));
enabled_bar
};