renovate
afcce58d6d
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [indicatif](https://github.com/console-rs/indicatif) | dependencies | minor | `0.16.2` -> `0.17.8` | > ❗ **Important** > > Release Notes retrieval for this PR were skipped because no github.com credentials were available. > If you are self-hosted, please see [this instruction](https://github.com/renovatebot/renovate/blob/master/docs/usage/examples/self-hosting.md#githubcom-token-for-release-notes). --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMzQuMSIsInVwZGF0ZWRJblZlciI6IjM3LjI3Mi4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> Co-authored-by: Renovate Bot <renovate@kemitix.net> Co-authored-by: Paul Campbell <pcampbell@kemitix.net> Reviewed-on: #24 Co-authored-by: renovate <renovate@noreply.kemitix.net> Co-committed-by: renovate <renovate@noreply.kemitix.net>
187 lines
5.1 KiB
Rust
187 lines
5.1 KiB
Rust
use std::fmt::{Debug, Display};
|
|
|
|
use flexi_logger::FlexiLoggerError;
|
|
use thiserror::Error;
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum ErrorKind {
|
|
#[error("[EpubError]: {0}")]
|
|
EpubError(String),
|
|
#[error("[HTTPError]: {0}")]
|
|
HTTPError(String),
|
|
#[error("[IOError]: {0}")]
|
|
IOError(String),
|
|
#[error("[UTF8Error]: {0}")]
|
|
UTF8Error(String),
|
|
#[error("[ReadabilityError]: {0}")]
|
|
ReadabilityError(String),
|
|
#[error("[TemplateError]: {0}")]
|
|
TemplateError(String),
|
|
}
|
|
|
|
#[derive(Error, Debug)]
|
|
#[error("{kind}")]
|
|
/// Used to represent errors from downloading images. Errors from here are used solely for debugging
|
|
/// as they are considered recoverable.
|
|
pub struct ImgError {
|
|
kind: ErrorKind,
|
|
url: Option<String>,
|
|
}
|
|
|
|
impl ImgError {
|
|
pub fn with_kind(kind: ErrorKind) -> Self {
|
|
ImgError { url: None, kind }
|
|
}
|
|
|
|
pub fn set_url(&mut self, url: &str) {
|
|
self.url = Some(url.to_string());
|
|
}
|
|
|
|
pub fn url(&self) -> &Option<String> {
|
|
&self.url
|
|
}
|
|
}
|
|
|
|
impl From<ErrorKind> for ImgError {
|
|
fn from(kind: ErrorKind) -> Self {
|
|
ImgError::with_kind(kind)
|
|
}
|
|
}
|
|
|
|
impl From<surf::Error> for ImgError {
|
|
fn from(err: surf::Error) -> Self {
|
|
ImgError::with_kind(ErrorKind::HTTPError(err.to_string()))
|
|
}
|
|
}
|
|
|
|
impl From<url::ParseError> for ImgError {
|
|
fn from(err: url::ParseError) -> Self {
|
|
ImgError::with_kind(ErrorKind::HTTPError(err.to_string()))
|
|
}
|
|
}
|
|
|
|
impl From<std::io::Error> for ImgError {
|
|
fn from(err: std::io::Error) -> Self {
|
|
ImgError::with_kind(ErrorKind::IOError(err.to_string()))
|
|
}
|
|
}
|
|
|
|
#[derive(Error, Debug)]
|
|
#[error("{kind}")]
|
|
pub struct PaperoniError {
|
|
article_source: Option<String>,
|
|
kind: ErrorKind,
|
|
}
|
|
|
|
impl PaperoniError {
|
|
pub fn with_kind(kind: ErrorKind) -> Self {
|
|
PaperoniError {
|
|
article_source: None,
|
|
kind,
|
|
}
|
|
}
|
|
|
|
pub fn kind(&self) -> &ErrorKind {
|
|
&self.kind
|
|
}
|
|
|
|
pub fn article_source(&self) -> &Option<String> {
|
|
&self.article_source
|
|
}
|
|
|
|
pub fn set_article_source(&mut self, article_source: &str) {
|
|
self.article_source = Some(article_source.to_owned());
|
|
}
|
|
}
|
|
|
|
impl From<ErrorKind> for PaperoniError {
|
|
fn from(kind: ErrorKind) -> Self {
|
|
PaperoniError::with_kind(kind)
|
|
}
|
|
}
|
|
|
|
impl From<eyre::Error> for PaperoniError {
|
|
fn from(err: eyre::Error) -> Self {
|
|
PaperoniError::with_kind(ErrorKind::EpubError(err.to_string()))
|
|
}
|
|
}
|
|
|
|
impl From<surf::Error> for PaperoniError {
|
|
fn from(err: surf::Error) -> Self {
|
|
PaperoniError::with_kind(ErrorKind::HTTPError(err.to_string()))
|
|
}
|
|
}
|
|
|
|
impl From<url::ParseError> for PaperoniError {
|
|
fn from(err: url::ParseError) -> Self {
|
|
PaperoniError::with_kind(ErrorKind::HTTPError(err.to_string()))
|
|
}
|
|
}
|
|
|
|
impl From<std::io::Error> for PaperoniError {
|
|
fn from(err: std::io::Error) -> Self {
|
|
PaperoniError::with_kind(ErrorKind::IOError(err.to_string()))
|
|
}
|
|
}
|
|
|
|
impl From<std::str::Utf8Error> for PaperoniError {
|
|
fn from(err: std::str::Utf8Error) -> Self {
|
|
PaperoniError::with_kind(ErrorKind::UTF8Error(err.to_string()))
|
|
}
|
|
}
|
|
|
|
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)]
|
|
FlexiError(#[from] FlexiLoggerError),
|
|
#[error("Unable to get user directories for logging purposes")]
|
|
UserDirectoriesError,
|
|
#[error("Can't create log directory: {0}")]
|
|
CreateLogDirectoryError(#[from] std::io::Error),
|
|
}
|
|
|
|
// dumb hack to allow for comparing errors in testing.
|
|
// derive macros cannot be used because underlying errors like io::Error do not derive PartialEq
|
|
impl PartialEq for LogError {
|
|
fn eq(&self, other: &Self) -> bool {
|
|
format!("{:?}", self) == format!("{:?}", other)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum CliError<BuilderError: Debug + Display> {
|
|
#[error("Failed to open file with urls: {0}")]
|
|
UrlFileError(#[from] std::io::Error),
|
|
#[error("Failed to parse max connection value: {0}")]
|
|
InvalidMaxConnectionCount(#[from] std::num::ParseIntError),
|
|
#[error("No urls were provided")]
|
|
NoUrls,
|
|
#[error("Failed to build cli application: {0}")]
|
|
AppBuildError(BuilderError),
|
|
#[error("Invalid output path name for merged epubs: {0}")]
|
|
InvalidOutputPath(String),
|
|
#[error("Wrong output directory")]
|
|
WrongOutputDirectory,
|
|
#[error("Output directory does not exist")]
|
|
OutputDirectoryNotExists,
|
|
#[error("Unable to start logger!\n{0}")]
|
|
LogError(#[from] LogError),
|
|
#[error("The --inline-toc flag can only be used when exporting to epub")]
|
|
WrongExportInliningToC,
|
|
#[error("The --inline-images flag can only be used when exporting to html")]
|
|
WrongExportInliningImages,
|
|
}
|
|
|
|
// dumb hack to allow for comparing errors in testing.
|
|
// derive macros cannot be used because underlying errors like io::Error do not derive PartialEq
|
|
impl<T: Debug + Display> PartialEq for CliError<T> {
|
|
fn eq(&self, other: &Self) -> bool {
|
|
format!("{:?}", self) == format!("{:?}", other)
|
|
}
|
|
}
|