Skip to content

Commit

Permalink
chore: gracefully handle a impossible err
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Dec 6, 2024
1 parent 1ffc552 commit aa6b87e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2422,12 +2422,20 @@ fn replace_params_with_file(
request_payload: &mut serde_json::Value,
params_value: serde_json::Value,
) -> Result<Option<String>, String> {
let file_path = std::path::PathBuf::from("broadcast_tx_commit__params_field.json");

let total_params_length = {
match serde_json::to_vec_pretty(&params_value) {
Ok(serialized) => serialized.len(),
// skipping logic with replacing request's field, though
// this branch is supposed to be unreachable
Err(_err) => 0,
Err(err) => {
return Err(format!(
"Failed to save payload to `{}`. Serialization error:\n{}",
&file_path.display(),
indent_payload(&format!("{:#?}", err))
));
}
}
};

Expand All @@ -2442,8 +2450,6 @@ fn replace_params_with_file(
serde_json::Value::Object(map)
};

let file_path = std::path::PathBuf::from("broadcast_tx_commit__params_field.json");

let result = match std::fs::File::create(&file_path) {
Ok(mut file) => match serde_json::to_vec_pretty(&file_content) {
Ok(buf) => match file.write(&buf) {
Expand Down

0 comments on commit aa6b87e

Please sign in to comment.