summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2020-07-02 08:33:35 +0800
committerSebastian Thiel <sebastian.thiel@icloud.com>2020-07-02 08:33:35 +0800
commitaf7a09c53faf9ebeeb8c0a15278b510738d1f34f (patch)
treeb111f49ee3ee6bed4044138e68662786635762dc
parent9ac025f7e546514581aaa96f96b8af476988d384 (diff)
Use 'anyhow' instead of 'failure' to simplify code and reduce bloat
-rw-r--r--Cargo.lock108
-rw-r--r--Cargo.toml3
-rw-r--r--src/aggregate.rs6
-rw-r--r--src/interactive/app/eventloop.rs16
-rw-r--r--src/interactive/app/handlers.rs4
-rw-r--r--src/interactive/app_test/journeys_readonly.rs12
-rw-r--r--src/interactive/app_test/journeys_with_writes.rs4
-rw-r--r--src/interactive/app_test/unit.rs6
-rw-r--r--src/interactive/app_test/utils.rs14
-rw-r--r--src/lib.rs1
-rw-r--r--src/main.rs11
-rw-r--r--src/traverse.rs6
-rw-r--r--tests/snapshots/failure-interactive-without-tty7
-rw-r--r--tests/snapshots/failure-no-arguments-multiple-input-paths-some-not-existing2
14 files changed, 47 insertions, 153 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 7e3f027..1f999c1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,21 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
-name = "addr2line"
-version = "0.12.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "602d785912f476e480434627e8732e6766b760c045bbf897d9dfaa9f4fbd399c"
-dependencies = [
- "gimli",
-]
-
-[[package]]
-name = "adler32"
-version = "1.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "567b077b825e468cc974f0020d4082ee6e03132512f207ef1a02fd5d00d1f32d"
-
-[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -25,6 +10,12 @@ dependencies = [
]
[[package]]
+name = "anyhow"
+version = "1.0.31"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "85bb70cc08ec97ca5450e6eba421deeea5f172c0fc61f78b5357b2a8e8be195f"
+
+[[package]]
name = "argh"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -71,20 +62,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
[[package]]
-name = "backtrace"
-version = "0.3.49"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "05100821de9e028f12ae3d189176b41ee198341eb8f369956407fea2f5cc666c"
-dependencies = [
- "addr2line",
- "cfg-if",
- "libc",
- "miniz_oxide",
- "object",
- "rustc-demangle",
-]
-
-[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -200,11 +177,10 @@ checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
name = "dua-cli"
version = "2.8.0"
dependencies = [
+ "anyhow",
"argh",
"atty",
"byte-unit",
- "failure",
- "failure-tools",
"filesize",
"flume",
"itertools",
@@ -227,37 +203,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
[[package]]
-name = "failure"
-version = "0.1.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86"
-dependencies = [
- "backtrace",
- "failure_derive",
-]
-
-[[package]]
-name = "failure-tools"
-version = "4.0.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "03d1b6907412387e932f12ad6e93adab19fed0ca10a03de8b744d275977d72ca"
-dependencies = [
- "failure",
-]
-
-[[package]]
-name = "failure_derive"
-version = "0.1.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
- "synstructure",
-]
-
-[[package]]
name = "filesize"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -282,12 +227,6 @@ dependencies = [
]
[[package]]
-name = "gimli"
-version = "0.21.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bcc8e0c9bce37868955864dbecd2b1ab2bdf967e6f28066d65aaac620444b65c"
-
-[[package]]
name = "heck"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -370,15 +309,6 @@ dependencies = [
]
[[package]]
-name = "miniz_oxide"
-version = "0.3.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435"
-dependencies = [
- "adler32",
-]
-
-[[package]]
name = "num_cpus"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -395,12 +325,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
[[package]]
-name = "object"
-version = "0.20.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5"
-
-[[package]]
name = "open"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -499,12 +423,6 @@ dependencies = [
]
[[package]]
-name = "rustc-demangle"
-version = "0.1.16"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
-
-[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -528,18 +446,6 @@ dependencies = [
]
[[package]]
-name = "synstructure"
-version = "0.12.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
- "unicode-xid",
-]
-
-[[package]]
name = "termion"
version = "1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 44fddcf..57829a1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,8 +10,6 @@ license = "MIT"
include = ["src/**/*", "Cargo.*", "LICENSE", "README.md", "CHANGELOG.md", "!**/*_test/*"]
[dependencies]
-failure = "0.1.1"
-failure-tools = "4.0.2"
argh = "0.1.3"
jwalk = "0.5.0"
byte-unit = "4"
@@ -27,6 +25,7 @@ num_cpus = "1.10.0"
unicode-segmentation = "1.3.0"
filesize = "0.2.0"
flume = {version = "0.7.1", default-features = false}
+anyhow = "1.0.31"
[[bin]]
name="dua"
diff --git a/src/aggregate.rs b/src/aggregate.rs
index fdc6694..d40a0cf 100644
--- a/src/aggregate.rs
+++ b/src/aggregate.rs
@@ -1,5 +1,5 @@
use crate::{crossdev, InodeFilter, WalkOptions, WalkResult};
-use failure::Error;
+use anyhow::Result;
use filesize::PathExt;
use std::borrow::Cow;
use std::{fmt, io, path::Path};
@@ -14,7 +14,7 @@ pub fn aggregate(
compute_total: bool,
sort_by_size_in_bytes: bool,
paths: impl IntoIterator<Item = impl AsRef<Path>>,
-) -> Result<(WalkResult, Statistics), Error> {
+) -> Result<(WalkResult, Statistics)> {
let mut res = WalkResult::default();
let mut stats = Statistics::default();
stats.smallest_file_in_bytes = u128::max_value();
@@ -125,7 +125,7 @@ fn write_path<C: fmt::Display>(
num_bytes: u128,
num_errors: u64,
path_color: C,
-) -> Result<(), io::Error> {
+) -> std::result::Result<(), io::Error> {
writeln!(
out,
"{byte_color}{:>byte_column_width$}{byte_color_reset} {path_color}{}{path_color_reset}{}",
diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs
index b34c170..c815ed4 100644
--- a/src/interactive/app/eventloop.rs
+++ b/src/interactive/app/eventloop.rs
@@ -4,11 +4,11 @@ use crate::interactive::{
ByteVisualization, CursorDirection, CursorMode, DisplayOptions, EntryDataBundle, MarkEntryMode,
SortMode,
};
+use anyhow::Result;
use dua::{
traverse::{Traversal, TreeIndex},
WalkOptions, WalkResult,
};
-use failure::Error;
use std::{collections::BTreeMap, io, path::PathBuf};
use termion::{event::Key, input::TermRead};
use tui::backend::Backend;
@@ -51,7 +51,7 @@ impl AppState {
traversal: &Traversal,
display: DisplayOptions,
terminal: &mut Terminal<B>,
- ) -> Result<(), Error>
+ ) -> Result<()>
where
B: Backend,
{
@@ -69,8 +69,8 @@ impl AppState {
traversal: &mut Traversal,
display: &mut DisplayOptions,
terminal: &mut Terminal<B>,
- keys: impl Iterator<Item = Result<Key, io::Error>>,
- ) -> Result<ProcessingResult, Error>
+ keys: impl Iterator<Item = std::result::Result<Key, io::Error>>,
+ ) -> Result<ProcessingResult>
where
B: Backend,
{
@@ -159,7 +159,7 @@ pub fn draw_window<B>(
window: &mut MainWindow,
props: MainWindowProps,
terminal: &mut Terminal<B>,
-) -> Result<(), Error>
+) -> Result<()>
where
B: Backend,
{
@@ -183,8 +183,8 @@ impl TerminalApp {
pub fn process_events<B>(
&mut self,
terminal: &mut Terminal<B>,
- keys: impl Iterator<Item = Result<Key, io::Error>>,
- ) -> Result<WalkResult, Error>
+ keys: impl Iterator<Item = std::result::Result<Key, io::Error>>,
+ ) -> Result<WalkResult>
where
B: Backend,
{
@@ -204,7 +204,7 @@ impl TerminalApp {
options: WalkOptions,
input: Vec<PathBuf>,
mode: Interaction,
- ) -> Result<Option<KeyboardInputAndApp>, Error>
+ ) -> Result<Option<KeyboardInputAndApp>>
where
B: Backend,
{
diff --git a/src/interactive/app/handlers.rs b/src/interactive/app/handlers.rs
index 44ebc3c..1758177 100644
--- a/src/interactive/app/handlers.rs
+++ b/src/interactive/app/handlers.rs
@@ -1,9 +1,7 @@
-use crate::interactive::widgets::MainWindow;
use crate::interactive::{
app::FocussedPane::*,
path_of, sorted_entries,
- widgets::MarkMode,
- widgets::{HelpPane, MarkPane},
+ widgets::{HelpPane, MainWindow, MarkMode, MarkPane},
AppState, DisplayOptions, EntryDataBundle,
};
use dua::traverse::{Traversal, TreeIndex};
diff --git a/src/interactive/app_test/journeys_readonly.rs b/src/interactive/app_test/journeys_readonly.rs
index 9461265..595491a 100644
--- a/src/interactive/app_test/journeys_readonly.rs
+++ b/src/interactive/app_test/journeys_readonly.rs
@@ -1,18 +1,18 @@
-use crate::{
- interactive::app_test::utils::{
+use crate::interactive::{
+ app_test::utils::{
fixture_str, index_by_name, initialized_app_and_terminal_from_fixture, node_by_index,
node_by_name,
},
- interactive::app_test::FIXTURE_PATH,
- interactive::SortMode,
+ app_test::FIXTURE_PATH,
+ SortMode,
};
-use failure::Error;
+use anyhow::Result;
use pretty_assertions::assert_eq;
use std::ffi::OsString;
use termion::input::TermRead;
#[test]
-fn simple_user_journey_read_only() -> Result<(), Error> {
+fn simple_user_journey_read_only() -> Result<()> {
let long_root = "sample-02/dir";
let short_root = "sample-01";
let (mut terminal, mut app) =
diff --git a/src/interactive/app_test/journeys_with_writes.rs b/src/interactive/app_test/journeys_with_writes.rs
index cbd51cd..061fb4b 100644
--- a/src/interactive/app_test/journeys_with_writes.rs
+++ b/src/interactive/app_test/journeys_with_writes.rs
@@ -1,13 +1,13 @@
use crate::interactive::app_test::utils::{
initialized_app_and_terminal_from_paths, WritableFixture,
};
-use failure::Error;
+use anyhow::Result;
use pretty_assertions::assert_eq;
use termion::event::Key;
use termion::input::TermRead;
#[test]
-fn basic_user_journey_with_deletion() -> Result<(), Error> {
+fn basic_user_journey_with_deletion() -> Result<()> {
let fixture = WritableFixture::from("sample-02");
let (mut terminal, mut app) = initialized_app_and_terminal_from_paths(&[fixture.root.clone()])?;
diff --git a/src/interactive/app_test/unit.rs b/src/interactive/app_test/unit.rs
index 71a90a9..e27d456 100644
--- a/src/interactive/app_test/unit.rs
+++ b/src/interactive/app_test/unit.rs
@@ -1,11 +1,11 @@
use crate::interactive::app_test::utils::{
debug, initialized_app_and_terminal_from_fixture, sample_01_tree, sample_02_tree,
};
-use failure::Error;
+use anyhow::Result;
use pretty_assertions::assert_eq;
#[test]
-fn it_can_handle_ending_traversal_reaching_top_but_skipping_levels() -> Result<(), Error> {
+fn it_can_handle_ending_traversal_reaching_top_but_skipping_levels() -> Result<()> {
let (_, app) = initialized_app_and_terminal_from_fixture(&["sample-01"])?;
let expected_tree = sample_01_tree();
@@ -18,7 +18,7 @@ fn it_can_handle_ending_traversal_reaching_top_but_skipping_levels() -> Result<(
}
#[test]
-fn it_can_handle_ending_traversal_without_reaching_the_top() -> Result<(), Error> {
+fn it_can_handle_ending_traversal_without_reaching_the_top() -> Result<()> {
let (_, app) = initialized_app_and_terminal_from_fixture(&["sample-02"])?;
let expected_tree = sample_02_tree();
diff --git a/src/interactive/app_test/utils.rs b/src/interactive/app_test/utils.rs
index ed94720..495ac01 100644
--- a/src/interactive/app_test/utils.rs
+++ b/src/interactive/app_test/utils.rs
@@ -1,12 +1,9 @@
-use crate::{
- interactive::app_test::FIXTURE_PATH,
- interactive::{Interaction, TerminalApp},
-};
+use crate::interactive::{app_test::FIXTURE_PATH, Interaction, TerminalApp};
+use anyhow::{Context, Error, Result};
use dua::{
traverse::{EntryData, Tree, TreeIndex},
ByteFormat, Color, TraversalSorting, WalkOptions,
};
-use failure::{Error, ResultExt};
use itertools::Itertools;
use jwalk::{DirEntry, WalkDir};
use petgraph::prelude::NodeIndex;
@@ -16,8 +13,7 @@ use std::{
fmt,
fs::{copy, create_dir_all, remove_dir, remove_file},
io::ErrorKind,
- path::Path,
- path::PathBuf,
+ path::{Path, PathBuf},
};
use tui::backend::TestBackend;
use tui_react::Terminal;
@@ -70,7 +66,7 @@ impl Drop for WritableFixture {
}
}
-fn delete_recursive(path: impl AsRef<Path>) -> Result<(), Error> {
+fn delete_recursive(path: impl AsRef<Path>) -> Result<()> {
let mut files: Vec<_> = Vec::new();
let mut dirs: Vec<_> = Vec::new();
@@ -95,7 +91,7 @@ fn delete_recursive(path: impl AsRef<Path>) -> Result<(), Error> {
.rev()
.map(|d| {
remove_dir(d)
- .with_context(|_| format!("Could not delete '{}'", d.display()))
+ .with_context(|| format!("Could not delete '{}'", d.display()))
.map_err(Error::from)
}),
)
diff --git a/src/lib.rs b/src/lib.rs
index 1e2a0c0..7988699 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,7 +1,6 @@
#![cfg_attr(windows, feature(windows_by_handle))]
#![forbid(unsafe_code)]
-extern crate failure;
extern crate jwalk;
mod aggregate;
diff --git a/src/main.rs b/src/main.rs
index 3630be3..8104490 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,9 +1,8 @@
#![forbid(unsafe_code)]
#![allow(clippy::match_bool)]
use crate::interactive::{Interaction, TerminalApp};
+use anyhow::{Context, Result};
use dua::{ByteFormat, Color, TraversalSorting};
-use failure::{Error, ResultExt};
-use failure_tools::ok_or_exit;
use std::{fs, io, io::Write, path::PathBuf, process};
use termion::{raw::IntoRawMode, screen::AlternateScreen};
use tui::backend::TermionBackend;
@@ -12,7 +11,7 @@ use tui_react::Terminal;
mod interactive;
mod options;
-fn run() -> Result<(), Error> {
+fn main() -> Result<()> {
use options::*;
let opt: options::Args = argh::from_env();
@@ -35,7 +34,7 @@ fn run() -> Result<(), Error> {
let mut terminal = {
let stdout = io::stdout()
.into_raw_mode()
- .with_context(|_| "Interactive mode requires a connected terminal")?;
+ .with_context(|| "Interactive mode requires a connected terminal")?;
let stdout = AlternateScreen::from(stdout);
let backend = TermionBackend::new(stdout);
Terminal::new(backend)?
@@ -129,7 +128,3 @@ fn cwd_dirlist() -> Result<Vec<PathBuf>, io::Error> {
v.sort();
Ok(v)
}
-
-fn main() {
- ok_or_exit(run())
-}
diff --git a/src/traverse.rs b/src/traverse.rs
index d19dd9e..0b56aa8 100644
--- a/src/traverse.rs
+++ b/src/traverse.rs
@@ -1,5 +1,5 @@
use crate::{crossdev, get_size_or_panic, InodeFilter, WalkOptions};
-use failure::Error;
+use anyhow::Result;
use filesize::PathExt;
use petgraph::{graph::NodeIndex, stable_graph::StableGraph, Directed, Direction};
use std::{path::PathBuf, time::Duration, time::Instant};
@@ -37,8 +37,8 @@ impl Traversal {
pub fn from_walk(
mut walk_options: WalkOptions,
input: Vec<PathBuf>,
- mut update: impl FnMut(&mut Traversal) -> Result<bool, Error>,
- ) -> Result<Option<Traversal>, Error> {
+ mut update: impl FnMut(&mut Traversal) -> Result<bool>,
+ ) -> Result<Option<Traversal>> {
fn set_size_or_panic(tree: &mut Tree, node_idx: TreeIndex, current_size_at_depth: u128) {
tree.node_weight_mut(node_idx)
.expect("node for parent index we just retrieved")
diff --git a/tests/snapshots/failure-interactive-without-tty b/tests/snapshots/failure-interactive-without-tty
index 9d3cd92..d5d704b 100644
--- a/tests/snapshots/failure-interactive-without-tty
+++ b/tests/snapshots/failure-interactive-without-tty
@@ -1,3 +1,4 @@
-error: Interactive mode requires a connected terminal
-Caused by:
- 1: Inappropriate ioctl for device (os error 25) \ No newline at end of file
+Error: Interactive mode requires a connected terminal
+
+Caused by:
+ Inappropriate ioctl for device (os error 25) \ No newline at end of file
diff --git a/tests/snapshots/failure-no-arguments-multiple-input-paths-some-not-existing b/tests/snapshots/failure-no-arguments-multiple-input-paths-some-not-existing
index e35c8e7..59f080a 100644
--- a/tests/snapshots/failure-no-arguments-multiple-input-paths-some-not-existing
+++ b/tests/snapshots/failure-no-arguments-multiple-input-paths-some-not-existing
@@ -1 +1 @@
-error: No such file or directory (os error 2) \ No newline at end of file
+Error: No such file or directory (os error 2) \ No newline at end of file