Skip to content

Commit af7a09c

Browse files
committed
Use 'anyhow' instead of 'failure' to simplify code and reduce bloat
1 parent 9ac025f commit af7a09c

File tree

14 files changed

+47
-153
lines changed

14 files changed

+47
-153
lines changed

Cargo.lock

Lines changed: 7 additions & 101 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ license = "MIT"
1010
include = ["src/**/*", "Cargo.*", "LICENSE", "README.md", "CHANGELOG.md", "!**/*_test/*"]
1111

1212
[dependencies]
13-
failure = "0.1.1"
14-
failure-tools = "4.0.2"
1513
argh = "0.1.3"
1614
jwalk = "0.5.0"
1715
byte-unit = "4"
@@ -27,6 +25,7 @@ num_cpus = "1.10.0"
2725
unicode-segmentation = "1.3.0"
2826
filesize = "0.2.0"
2927
flume = {version = "0.7.1", default-features = false}
28+
anyhow = "1.0.31"
3029

3130
[[bin]]
3231
name="dua"

src/aggregate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{crossdev, InodeFilter, WalkOptions, WalkResult};
2-
use failure::Error;
2+
use anyhow::Result;
33
use filesize::PathExt;
44
use std::borrow::Cow;
55
use std::{fmt, io, path::Path};
@@ -14,7 +14,7 @@ pub fn aggregate(
1414
compute_total: bool,
1515
sort_by_size_in_bytes: bool,
1616
paths: impl IntoIterator<Item = impl AsRef<Path>>,
17-
) -> Result<(WalkResult, Statistics), Error> {
17+
) -> Result<(WalkResult, Statistics)> {
1818
let mut res = WalkResult::default();
1919
let mut stats = Statistics::default();
2020
stats.smallest_file_in_bytes = u128::max_value();
@@ -125,7 +125,7 @@ fn write_path<C: fmt::Display>(
125125
num_bytes: u128,
126126
num_errors: u64,
127127
path_color: C,
128-
) -> Result<(), io::Error> {
128+
) -> std::result::Result<(), io::Error> {
129129
writeln!(
130130
out,
131131
"{byte_color}{:>byte_column_width$}{byte_color_reset} {path_color}{}{path_color_reset}{}",

src/interactive/app/eventloop.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use crate::interactive::{
44
ByteVisualization, CursorDirection, CursorMode, DisplayOptions, EntryDataBundle, MarkEntryMode,
55
SortMode,
66
};
7+
use anyhow::Result;
78
use dua::{
89
traverse::{Traversal, TreeIndex},
910
WalkOptions, WalkResult,
1011
};
11-
use failure::Error;
1212
use std::{collections::BTreeMap, io, path::PathBuf};
1313
use termion::{event::Key, input::TermRead};
1414
use tui::backend::Backend;
@@ -51,7 +51,7 @@ impl AppState {
5151
traversal: &Traversal,
5252
display: DisplayOptions,
5353
terminal: &mut Terminal<B>,
54-
) -> Result<(), Error>
54+
) -> Result<()>
5555
where
5656
B: Backend,
5757
{
@@ -69,8 +69,8 @@ impl AppState {
6969
traversal: &mut Traversal,
7070
display: &mut DisplayOptions,
7171
terminal: &mut Terminal<B>,
72-
keys: impl Iterator<Item = Result<Key, io::Error>>,
73-
) -> Result<ProcessingResult, Error>
72+
keys: impl Iterator<Item = std::result::Result<Key, io::Error>>,
73+
) -> Result<ProcessingResult>
7474
where
7575
B: Backend,
7676
{
@@ -159,7 +159,7 @@ pub fn draw_window<B>(
159159
window: &mut MainWindow,
160160
props: MainWindowProps,
161161
terminal: &mut Terminal<B>,
162-
) -> Result<(), Error>
162+
) -> Result<()>
163163
where
164164
B: Backend,
165165
{
@@ -183,8 +183,8 @@ impl TerminalApp {
183183
pub fn process_events<B>(
184184
&mut self,
185185
terminal: &mut Terminal<B>,
186-
keys: impl Iterator<Item = Result<Key, io::Error>>,
187-
) -> Result<WalkResult, Error>
186+
keys: impl Iterator<Item = std::result::Result<Key, io::Error>>,
187+
) -> Result<WalkResult>
188188
where
189189
B: Backend,
190190
{
@@ -204,7 +204,7 @@ impl TerminalApp {
204204
options: WalkOptions,
205205
input: Vec<PathBuf>,
206206
mode: Interaction,
207-
) -> Result<Option<KeyboardInputAndApp>, Error>
207+
) -> Result<Option<KeyboardInputAndApp>>
208208
where
209209
B: Backend,
210210
{

src/interactive/app/handlers.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
use crate::interactive::widgets::MainWindow;
21
use crate::interactive::{
32
app::FocussedPane::*,
43
path_of, sorted_entries,
5-
widgets::MarkMode,
6-
widgets::{HelpPane, MarkPane},
4+
widgets::{HelpPane, MainWindow, MarkMode, MarkPane},
75
AppState, DisplayOptions, EntryDataBundle,
86
};
97
use dua::traverse::{Traversal, TreeIndex};

src/interactive/app_test/journeys_readonly.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
use crate::{
2-
interactive::app_test::utils::{
1+
use crate::interactive::{
2+
app_test::utils::{
33
fixture_str, index_by_name, initialized_app_and_terminal_from_fixture, node_by_index,
44
node_by_name,
55
},
6-
interactive::app_test::FIXTURE_PATH,
7-
interactive::SortMode,
6+
app_test::FIXTURE_PATH,
7+
SortMode,
88
};
9-
use failure::Error;
9+
use anyhow::Result;
1010
use pretty_assertions::assert_eq;
1111
use std::ffi::OsString;
1212
use termion::input::TermRead;
1313

1414
#[test]
15-
fn simple_user_journey_read_only() -> Result<(), Error> {
15+
fn simple_user_journey_read_only() -> Result<()> {
1616
let long_root = "sample-02/dir";
1717
let short_root = "sample-01";
1818
let (mut terminal, mut app) =

src/interactive/app_test/journeys_with_writes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use crate::interactive::app_test::utils::{
22
initialized_app_and_terminal_from_paths, WritableFixture,
33
};
4-
use failure::Error;
4+
use anyhow::Result;
55
use pretty_assertions::assert_eq;
66
use termion::event::Key;
77
use termion::input::TermRead;
88

99
#[test]
10-
fn basic_user_journey_with_deletion() -> Result<(), Error> {
10+
fn basic_user_journey_with_deletion() -> Result<()> {
1111
let fixture = WritableFixture::from("sample-02");
1212
let (mut terminal, mut app) = initialized_app_and_terminal_from_paths(&[fixture.root.clone()])?;
1313

src/interactive/app_test/unit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::interactive::app_test::utils::{
22
debug, initialized_app_and_terminal_from_fixture, sample_01_tree, sample_02_tree,
33
};
4-
use failure::Error;
4+
use anyhow::Result;
55
use pretty_assertions::assert_eq;
66

77
#[test]
8-
fn it_can_handle_ending_traversal_reaching_top_but_skipping_levels() -> Result<(), Error> {
8+
fn it_can_handle_ending_traversal_reaching_top_but_skipping_levels() -> Result<()> {
99
let (_, app) = initialized_app_and_terminal_from_fixture(&["sample-01"])?;
1010
let expected_tree = sample_01_tree();
1111

@@ -18,7 +18,7 @@ fn it_can_handle_ending_traversal_reaching_top_but_skipping_levels() -> Result<(
1818
}
1919

2020
#[test]
21-
fn it_can_handle_ending_traversal_without_reaching_the_top() -> Result<(), Error> {
21+
fn it_can_handle_ending_traversal_without_reaching_the_top() -> Result<()> {
2222
let (_, app) = initialized_app_and_terminal_from_fixture(&["sample-02"])?;
2323
let expected_tree = sample_02_tree();
2424

0 commit comments

Comments
 (0)