Skip to content

Commit

Permalink
If parsing the input fails, give a partial crash report, instead of b…
Browse files Browse the repository at this point in the history
…orking
  • Loading branch information
danielsn committed Jun 5, 2024
1 parent 5a70cc7 commit 73d99ac
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crashtracker/src/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ enum StdinState {
Counters,
Done,
File(String, Vec<String>),
InternalError(String),
Metadata,
SigInfo,
StackTrace(Vec<StackFrame>),
Expand Down Expand Up @@ -137,6 +138,8 @@ fn process_line(
StdinState::File(name, contents)
}

StdinState::InternalError(e) => anyhow::bail!("Can't continue after internal error {e}"),

StdinState::Metadata if line.starts_with(DD_CRASHTRACK_END_METADATA) => StdinState::Waiting,
StdinState::Metadata => {
let metadata = serde_json::from_str(&line)?;
Expand Down Expand Up @@ -207,7 +210,14 @@ fn receive_report(stream: impl std::io::BufRead) -> anyhow::Result<CrashReportSt
//TODO: This assumes that the input is valid UTF-8.
for line in stream.lines() {
let line = line?;
stdin_state = process_line(&mut crashinfo, &mut config, line, stdin_state)?;
match process_line(&mut crashinfo, &mut config, line, stdin_state) {
Ok(next_state) => stdin_state = next_state,
Err(e) => {
// If the input is corrupted, stop and salvage what we can
stdin_state = StdinState::InternalError(e.to_string());
break;
}
}
}

if !crashinfo.crash_seen() {
Expand Down

0 comments on commit 73d99ac

Please sign in to comment.