Skip to content

Commit 677fc49

Browse files
committed
Fix error message when running check mode on stdin
1 parent 677ad44 commit 677fc49

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- `Default` trait impl for `PasFmtConfiguration`.
1313

14+
### Changed
15+
16+
- Error message when `--mode=check` fails on stdin, now reads `<stdin> is incorrectly formatted`.
17+
1418
### Added
1519

1620
- `try_create` and `validate` functions to the type generated by the `pasfmt_config!` macro.

orchestrator/src/formatting_orchestrator.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::borrow::Cow;
22

33
use crate::{command_line::FormatMode, file_formatter::FileFormatter};
4-
use anyhow::anyhow;
4+
use anyhow::{anyhow, bail};
55
use log::LevelFilter;
66

77
pub trait FormatterConfiguration {
@@ -30,21 +30,26 @@ fn check<T: FormatterConfiguration>(
3030
config: &T,
3131
file_formatter: &FileFormatter,
3232
) -> anyhow::Result<()> {
33-
let check_results = if config.is_stdin() {
34-
vec![file_formatter.check_stdin()]
33+
if config.is_stdin() {
34+
if file_formatter.check_stdin().is_err() {
35+
bail!("<stdin> is incorrectly formatted");
36+
}
3537
} else {
36-
file_formatter.check_files(&config.get_paths()?)
37-
};
38+
let fail_count = file_formatter
39+
.check_files(&config.get_paths()?)
40+
.iter()
41+
.filter(|r| r.is_err())
42+
.count();
3843

39-
let fail_count = check_results.iter().filter(|r| r.is_err()).count();
40-
if fail_count > 0 {
41-
Err(anyhow!(
42-
"{fail_count} {} incorrectly formatted",
43-
plural(fail_count, "file is", "files are")
44-
))
45-
} else {
46-
Ok(())
44+
if fail_count > 0 {
45+
bail!(
46+
"{fail_count} {} incorrectly formatted",
47+
plural(fail_count, "file is", "files are")
48+
)
49+
}
4750
}
51+
52+
Ok(())
4853
}
4954

5055
pub struct FormattingOrchestrator;

0 commit comments

Comments
 (0)