From 702cb198da986203aefe9c2fa6d024d8cbe96346 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Wed, 22 Apr 2020 21:45:47 +0200 Subject: Rename error module --- src/assets.rs | 2 +- src/assets_metadata.rs | 2 +- src/bin/bat/app.rs | 2 +- src/bin/bat/assets.rs | 2 +- src/bin/bat/config.rs | 2 +- src/bin/bat/main.rs | 2 +- src/controller.rs | 2 +- src/error.rs | 34 ++++++++++++++++++++++++++++++++++ src/errors.rs | 34 ---------------------------------- src/input.rs | 2 +- src/lib.rs | 4 ++-- src/line_range.rs | 2 +- src/output.rs | 2 +- src/pretty_printer.rs | 2 +- src/printer.rs | 2 +- src/style.rs | 2 +- src/syntax_mapping.rs | 2 +- 17 files changed, 50 insertions(+), 50 deletions(-) create mode 100644 src/error.rs delete mode 100644 src/errors.rs (limited to 'src') diff --git a/src/assets.rs b/src/assets.rs index 355c8d73..cc6f0d98 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -9,7 +9,7 @@ use syntect::highlighting::{Theme, ThemeSet}; use syntect::parsing::{SyntaxReference, SyntaxSet, SyntaxSetBuilder}; use crate::assets_metadata::AssetsMetadata; -use crate::errors::*; +use crate::error::*; use crate::input::{InputReader, OpenedInput, OpenedInputKind}; use crate::syntax_mapping::{MappingTarget, SyntaxMapping}; diff --git a/src/assets_metadata.rs b/src/assets_metadata.rs index d4aaaea1..da0ed88f 100644 --- a/src/assets_metadata.rs +++ b/src/assets_metadata.rs @@ -5,7 +5,7 @@ use std::time::SystemTime; use semver::Version; use serde::{Deserialize, Serialize}; -use crate::errors::*; +use crate::error::*; #[derive(Debug, PartialEq, Default, Serialize, Deserialize)] pub struct AssetsMetadata { diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 7b4bb38d..b47553f3 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -16,7 +16,7 @@ use console::Term; use bat::{ assets::HighlightingAssets, config::{Config, PagingMode}, - errors::*, + error::*, input::Input, line_range::{HighlightedLineRanges, LineRange, LineRanges}, style::{StyleComponent, StyleComponents}, diff --git a/src/bin/bat/assets.rs b/src/bin/bat/assets.rs index 1c937433..c0abfb90 100644 --- a/src/bin/bat/assets.rs +++ b/src/bin/bat/assets.rs @@ -7,7 +7,7 @@ use crate::directories::PROJECT_DIRS; use bat::assets::HighlightingAssets; use bat::assets_metadata::AssetsMetadata; -use bat::errors::*; +use bat::error::*; pub fn config_dir() -> Cow<'static, str> { PROJECT_DIRS.config_dir().to_string_lossy() diff --git a/src/bin/bat/config.rs b/src/bin/bat/config.rs index 889ec5d4..38bac82f 100644 --- a/src/bin/bat/config.rs +++ b/src/bin/bat/config.rs @@ -14,7 +14,7 @@ pub fn config_file() -> PathBuf { .unwrap_or_else(|| PROJECT_DIRS.config_dir().join("config")) } -pub fn generate_config_file() -> bat::errors::Result<()> { +pub fn generate_config_file() -> bat::error::Result<()> { let config_file = config_file(); if config_file.exists() { println!( diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index 03dee71e..818286d6 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -29,7 +29,7 @@ use bat::{ assets::HighlightingAssets, config::Config, controller::Controller, - errors::*, + error::*, input::Input, style::{StyleComponent, StyleComponents}, }; diff --git a/src/controller.rs b/src/controller.rs index 1ce8f965..b173f307 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -4,7 +4,7 @@ use crate::assets::HighlightingAssets; use crate::config::Config; #[cfg(feature = "paging")] use crate::config::PagingMode; -use crate::errors::*; +use crate::error::*; use crate::input::{Input, InputKind, InputReader, OpenedInput}; use crate::line_range::{LineRanges, RangeCheckResult}; use crate::output::OutputType; diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 00000000..cabf4f2a --- /dev/null +++ b/src/error.rs @@ -0,0 +1,34 @@ +use error_chain::error_chain; + +error_chain! { + foreign_links { + Clap(::clap::Error) #[cfg(feature = "application")]; + Io(::std::io::Error); + SyntectError(::syntect::LoadingError); + ParseIntError(::std::num::ParseIntError); + GlobParsingError(::globset::Error); + SerdeYamlError(::serde_yaml::Error); + } +} + +pub fn default_error_handler(error: &Error) { + use ansi_term::Colour::Red; + + match error { + Error(ErrorKind::Io(ref io_error), _) + if io_error.kind() == ::std::io::ErrorKind::BrokenPipe => + { + ::std::process::exit(0); + } + Error(ErrorKind::SerdeYamlError(_), _) => { + eprintln!( + "{}: Error while parsing metadata.yaml file: {}", + Red.paint("[bat error]"), + error + ); + } + _ => { + eprintln!("{}: {}", Red.paint("[bat error]"), error); + } + }; +} diff --git a/src/errors.rs b/src/errors.rs deleted file mode 100644 index cabf4f2a..00000000 --- a/src/errors.rs +++ /dev/null @@ -1,34 +0,0 @@ -use error_chain::error_chain; - -error_chain! { - foreign_links { - Clap(::clap::Error) #[cfg(feature = "application")]; - Io(::std::io::Error); - SyntectError(::syntect::LoadingError); - ParseIntError(::std::num::ParseIntError); - GlobParsingError(::globset::Error); - SerdeYamlError(::serde_yaml::Error); - } -} - -pub fn default_error_handler(error: &Error) { - use ansi_term::Colour::Red; - - match error { - Error(ErrorKind::Io(ref io_error), _) - if io_error.kind() == ::std::io::ErrorKind::BrokenPipe => - { - ::std::process::exit(0); - } - Error(ErrorKind::SerdeYamlError(_), _) => { - eprintln!( - "{}: Error while parsing metadata.yaml file: {}", - Red.paint("[bat error]"), - error - ); - } - _ => { - eprintln!("{}: {}", Red.paint("[bat error]"), error); - } - }; -} diff --git a/src/input.rs b/src/input.rs index 95b4eff3..f155c614 100644 --- a/src/input.rs +++ b/src/input.rs @@ -4,7 +4,7 @@ use std::io::{self, BufRead, BufReader, Read}; use content_inspector::{self, ContentType}; -use crate::errors::*; +use crate::error::*; const THEME_PREVIEW_FILE: &[u8] = include_bytes!("../assets/theme_preview.rs"); diff --git a/src/lib.rs b/src/lib.rs index e6cfd4c8..b57247a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,7 +15,7 @@ //! .input_from_bytes(b"Hello world!\n") //! .language("html") //! .print() -//! .expect("no errors"); +//! .unwrap(); //! ``` pub mod assets; @@ -24,7 +24,7 @@ pub mod config; pub mod controller; mod decorations; mod diff; -pub mod errors; +pub mod error; pub mod input; mod less; pub mod line_range; diff --git a/src/line_range.rs b/src/line_range.rs index 0abbb7ac..ba855fcb 100644 --- a/src/line_range.rs +++ b/src/line_range.rs @@ -1,4 +1,4 @@ -use crate::errors::*; +use crate::error::*; #[derive(Debug, Clone)] pub struct LineRange { diff --git a/src/output.rs b/src/output.rs index 0cfed062..8c1b111f 100644 --- a/src/output.rs +++ b/src/output.rs @@ -4,7 +4,7 @@ use std::process::Child; #[cfg(feature = "paging")] use crate::config::PagingMode; -use crate::errors::*; +use crate::error::*; #[cfg(feature = "paging")] use crate::less::retrieve_less_version; diff --git a/src/pretty_printer.rs b/src/pretty_printer.rs index db64292b..27794201 100644 --- a/src/pretty_printer.rs +++ b/src/pretty_printer.rs @@ -7,7 +7,7 @@ use crate::{ assets::HighlightingAssets, config::Config, controller::Controller, - errors::Result, + error::Result, input::Input, line_range::{HighlightedLineRanges, LineRanges}, style::{StyleComponent, StyleComponents}, diff --git a/src/printer.rs b/src/printer.rs index cdd1d8b0..b40e1a69 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -25,7 +25,7 @@ use crate::decorations::LineChangesDecoration; use crate::decorations::{Decoration, GridBorderDecoration, LineNumberDecoration}; #[cfg(feature = "git")] use crate::diff::{get_git_diff, LineChanges}; -use crate::errors::*; +use crate::error::*; use crate::input::{OpenedInput, OpenedInputKind}; use crate::line_range::RangeCheckResult; use crate::preprocessor::{expand_tabs, replace_nonprintable}; diff --git a/src/style.rs b/src/style.rs index ffa232ab..24fffd6b 100644 --- a/src/style.rs +++ b/src/style.rs @@ -1,7 +1,7 @@ use std::collections::HashSet; use std::str::FromStr; -use crate::errors::*; +use crate::error::*; #[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)] pub enum StyleComponent { diff --git a/src/syntax_mapping.rs b/src/syntax_mapping.rs index 72cb021c..259f8212 100644 --- a/src/syntax_mapping.rs +++ b/src/syntax_mapping.rs @@ -1,6 +1,6 @@ use std::path::Path; -use crate::errors::Result; +use crate::error::Result; use globset::{Candidate, GlobBuilder, GlobMatcher}; -- cgit v1.2.3