Skip to content

Commit 0cf6e7c

Browse files
fix(cli): prevent crash when parsing stdin
When we are parsing stdin via a pipe or heredoc, the source count is 0 (unsigned) so the XML output crashes while trying to subtract from it.
1 parent 1dc4804 commit 0cf6e7c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

crates/cli/src/parse.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,23 @@ impl ParseSummary {
230230
}
231231
}
232232

233-
#[derive(Serialize, Debug, Default)]
233+
#[derive(Serialize, Debug)]
234234
pub struct ParseStats {
235235
pub parse_summaries: Vec<ParseSummary>,
236236
pub cumulative_stats: Stats,
237237
pub source_count: usize,
238238
}
239239

240+
impl Default for ParseStats {
241+
fn default() -> Self {
242+
Self {
243+
parse_summaries: Vec::new(),
244+
cumulative_stats: Stats::default(),
245+
source_count: 1,
246+
}
247+
}
248+
}
249+
240250
#[derive(Serialize, ValueEnum, Debug, Copy, Clone, Default, Eq, PartialEq)]
241251
pub enum ParseDebugType {
242252
#[default]

0 commit comments

Comments
 (0)