chore: handle errors when converting line content to UTF-8 in hunks_by_filepath function

This commit is contained in:
Nikita Galaiko 2023-09-29 11:05:48 +02:00 committed by GitButler
parent 644a4ae3f3
commit ea097b7d8b

View File

@ -137,7 +137,11 @@ fn hunks_by_filepath(
match line.origin() {
'+' | '-' | ' ' => {
current_diff.push_str(&format!("{}", line.origin()));
current_diff.push_str(str::from_utf8(line.content()).unwrap());
current_diff.push_str(
str::from_utf8(line.content())
.map_err(|error| tracing::error!(?error, ?file_path))
.unwrap_or_default(),
);
current_binary = false;
}
'B' => {
@ -151,7 +155,11 @@ fn hunks_by_filepath(
current_binary = true;
}
_ => {
current_diff.push_str(std::str::from_utf8(line.content()).unwrap());
current_diff.push_str(
str::from_utf8(line.content())
.map_err(|error| tracing::error!(?error, ?file_path))
.unwrap_or_default(),
);
}
}