Skip to content

Commit

Permalink
fix: Return more precise errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Page committed Nov 23, 2020
1 parent 8ecffe7 commit b03df3a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 46 deletions.
81 changes: 47 additions & 34 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ toml = "0.5"
log = "0.4"
env_logger = "0.8"
bstr = "0.2"
ahash = "0.5.8"
ahash = "0.5.7"
difflib = "0.4"
proc-exit = "0.1"
proc-exit = "0.3"

[dev-dependencies]
assert_fs = "1.0"
Expand Down
8 changes: 4 additions & 4 deletions src/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub(crate) fn check_path(
parser: &typos::tokens::Parser,
dictionary: &dyn typos::Dictionary,
reporter: &dyn typos::report::Report,
) -> Result<(), anyhow::Error> {
) -> Result<(), ignore::Error> {
for entry in walk {
check_entry(entry, checks, parser, dictionary, reporter)?;
}
Expand All @@ -17,8 +17,8 @@ pub(crate) fn check_path_parallel(
parser: &typos::tokens::Parser,
dictionary: &dyn typos::Dictionary,
reporter: &dyn typos::report::Report,
) -> Result<(), anyhow::Error> {
let error: std::sync::Mutex<Result<(), anyhow::Error>> = std::sync::Mutex::new(Ok(()));
) -> Result<(), ignore::Error> {
let error: std::sync::Mutex<Result<(), ignore::Error>> = std::sync::Mutex::new(Ok(()));
walk.run(|| {
Box::new(|entry: Result<ignore::DirEntry, ignore::Error>| {
match check_entry(entry, checks, parser, dictionary, reporter) {
Expand All @@ -40,7 +40,7 @@ fn check_entry(
parser: &typos::tokens::Parser,
dictionary: &dyn typos::Dictionary,
reporter: &dyn typos::report::Report,
) -> Result<(), anyhow::Error> {
) -> Result<(), ignore::Error> {
let entry = entry?;
if entry.file_type().map(|t| t.is_file()).unwrap_or(true) {
let explicit = entry.depth() == 0;
Expand Down
16 changes: 10 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ mod dict;
mod diff;
mod replace;

use proc_exit::ProcessExitResultExt;
use proc_exit::WithCodeResultExt;

fn main() {
run().process_exit();
let result = run();
proc_exit::exit(result);
}

fn run() -> Result<(), proc_exit::Exit> {
fn run() -> proc_exit::ExitResult {
// clap's `get_matches` uses Failure rather than Usage, so bypass it for `get_matches_safe`.
let args = match args::Args::from_args_safe() {
Ok(args) => args,
Expand All @@ -29,7 +29,7 @@ fn run() -> Result<(), proc_exit::Exit> {
}
Err(e) => {
writeln!(std::io::stdout(), "{}", e)?;
return Ok(());
return proc_exit::Code::SUCCESS.ok();
}
};

Expand Down Expand Up @@ -130,7 +130,6 @@ fn run() -> Result<(), proc_exit::Exit> {
&dictionary,
reporter,
)
.with_code(proc_exit::Code::FAILURE)?;
} else {
checks::check_path_parallel(
walk.build_parallel(),
Expand All @@ -139,8 +138,13 @@ fn run() -> Result<(), proc_exit::Exit> {
&dictionary,
reporter,
)
.with_code(proc_exit::Code::FAILURE)?;
}
.map_err(|e| {
e.io_error()
.map(|i| proc_exit::Code::from(i.kind()))
.unwrap_or_default()
.with_message(e)
})?;
if status_reporter.typos_found() {
typos_found = true;
}
Expand Down

0 comments on commit b03df3a

Please sign in to comment.