Skip to content

Commit

Permalink
Use 'anyhow' instead of 'failure' to simplify code and reduce bloat
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 2, 2020
1 parent 9ac025f commit af7a09c
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 153 deletions.
108 changes: 7 additions & 101 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions src/aggregate.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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();
Expand Down Expand Up @@ -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}{}",
Expand Down
16 changes: 8 additions & 8 deletions src/interactive/app/eventloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,7 +51,7 @@ impl AppState {
traversal: &Traversal,
display: DisplayOptions,
terminal: &mut Terminal<B>,
) -> Result<(), Error>
) -> Result<()>
where
B: Backend,
{
Expand All @@ -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,
{
Expand Down Expand Up @@ -159,7 +159,7 @@ pub fn draw_window<B>(
window: &mut MainWindow,
props: MainWindowProps,
terminal: &mut Terminal<B>,
) -> Result<(), Error>
) -> Result<()>
where
B: Backend,
{
Expand All @@ -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,
{
Expand All @@ -204,7 +204,7 @@ impl TerminalApp {
options: WalkOptions,
input: Vec<PathBuf>,
mode: Interaction,
) -> Result<Option<KeyboardInputAndApp>, Error>
) -> Result<Option<KeyboardInputAndApp>>
where
B: Backend,
{
Expand Down
4 changes: 1 addition & 3 deletions src/interactive/app/handlers.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
12 changes: 6 additions & 6 deletions src/interactive/app_test/journeys_readonly.rs
Original file line number Diff line number Diff line change
@@ -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) =
Expand Down
4 changes: 2 additions & 2 deletions src/interactive/app_test/journeys_with_writes.rs
Original file line number Diff line number Diff line change
@@ -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()])?;

Expand Down
6 changes: 3 additions & 3 deletions src/interactive/app_test/unit.rs
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -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();

Expand Down

0 comments on commit af7a09c

Please sign in to comment.