Skip to content

Commit 127711c

Browse files
authored
fix: show error output when vp check --fix fmt fails (#798)
When fmt failed during `vp check --fix`, the error output was silently swallowed because display logic was gated behind `if !fix`. Now the error is shown via a new `print_error_block` helper that consolidates the repeated error display pattern across all three fmt error paths.
1 parent 80128dd commit 127711c

File tree

6 files changed

+58
-10
lines changed

6 files changed

+58
-10
lines changed

packages/cli/binding/src/cli.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,14 @@ fn print_summary_line(message: &str) {
10361036
}
10371037
}
10381038

1039+
fn print_error_block(error_msg: &str, combined_output: &str, summary_msg: &str) {
1040+
output::error(error_msg);
1041+
if !combined_output.trim().is_empty() {
1042+
print_stdout_block(combined_output);
1043+
}
1044+
print_summary_line(summary_msg);
1045+
}
1046+
10391047
fn print_pass_line(message: &str, detail: Option<&str>) {
10401048
if let Some(detail) = detail {
10411049
output::raw(&format!("{} {message} {}", "pass:".bright_blue().bold(), detail.dimmed()));
@@ -1200,11 +1208,11 @@ async fn execute_direct_subcommand(
12001208
));
12011209
}
12021210
None => {
1203-
output::error("Formatting could not start");
1204-
if !combined_output.trim().is_empty() {
1205-
print_stdout_block(&combined_output);
1206-
}
1207-
print_summary_line("Formatting failed before analysis started");
1211+
print_error_block(
1212+
"Formatting could not start",
1213+
&combined_output,
1214+
"Formatting failed before analysis started",
1215+
);
12081216
}
12091217
}
12101218
}
@@ -1216,6 +1224,13 @@ async fn execute_direct_subcommand(
12161224
);
12171225
}
12181226
if status != ExitStatus::SUCCESS {
1227+
if fix {
1228+
print_error_block(
1229+
"Formatting could not complete",
1230+
&combined_output,
1231+
"Formatting failed during fix",
1232+
);
1233+
}
12191234
resolver.cleanup_temp_files().await;
12201235
return Ok(status);
12211236
}
@@ -1326,11 +1341,11 @@ async fn execute_direct_subcommand(
13261341
} else {
13271342
format!("{}{}", captured.stdout, captured.stderr)
13281343
};
1329-
output::error("Formatting could not finish after lint fixes");
1330-
if !combined_output.trim().is_empty() {
1331-
print_stdout_block(&combined_output);
1332-
}
1333-
print_summary_line("Formatting failed after lint fixes were applied");
1344+
print_error_block(
1345+
"Formatting could not finish after lint fixes",
1346+
&combined_output,
1347+
"Formatting failed after lint fixes were applied",
1348+
);
13341349
resolver.cleanup_temp_files().await;
13351350
return Ok(status);
13361351
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "check-fix-missing-stderr",
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module"
6+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[1]> vp check --fix
2+
error: Formatting could not complete
3+
Failed to parse configuration.
4+
invalid type: string "invalid", expected struct Oxfmtrc
5+
6+
Formatting failed during fix
7+
8+
[1]> vp check
9+
error: Formatting could not start
10+
Failed to parse configuration.
11+
invalid type: string "invalid", expected struct Oxfmtrc
12+
13+
Formatting failed before analysis started
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function hello() {
2+
return "hello";
3+
}
4+
5+
export { hello };
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"commands": [
3+
"vp check --fix",
4+
"vp check"
5+
]
6+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
fmt: "invalid",
3+
};

0 commit comments

Comments
 (0)