fix(getblocktemplate): change error format in proposals (#6044)
* change error format in proposals * use trim_matches * make regex feature dependency * remove regex fully * remove char in comment to leave the file as it was before * remove assertion lines from snapshots
This commit is contained in:
parent
1b1201113e
commit
b327d5bb7d
|
@ -2,7 +2,7 @@
|
|||
//!
|
||||
//! `ProposalResponse` is the output of the `getblocktemplate` RPC method in 'proposal' mode.
|
||||
|
||||
use std::{error::Error, num::ParseIntError, str::FromStr, sync::Arc};
|
||||
use std::{num::ParseIntError, str::FromStr, sync::Arc};
|
||||
|
||||
use zebra_chain::{
|
||||
block::{self, Block, Height},
|
||||
|
@ -42,23 +42,21 @@ pub enum ProposalResponse {
|
|||
|
||||
impl ProposalResponse {
|
||||
/// Return a rejected response containing an error kind and detailed error info.
|
||||
pub fn rejected<S: ToString>(kind: S, error: BoxError) -> Self {
|
||||
let kind = kind.to_string();
|
||||
///
|
||||
/// Note: Error kind is currently ignored to match zcashd error format (`kebab-case` string).
|
||||
pub fn rejected<S: ToString>(_kind: S, error: BoxError) -> Self {
|
||||
// Make error `kebab-case` to match zcashd format.
|
||||
let error_kebab1 = format!("{error:?}")
|
||||
.replace(|c: char| !c.is_alphanumeric(), "-")
|
||||
.to_ascii_lowercase();
|
||||
// Remove consecutive duplicated `-` characters.
|
||||
let mut error_v: Vec<char> = error_kebab1.chars().collect();
|
||||
error_v.dedup_by(|a, b| a == &'-' && b == &'-');
|
||||
let error_kebab2: String = error_v.into_iter().collect();
|
||||
// Trim any leading or trailing `-` characters.
|
||||
let final_error = error_kebab2.trim_matches('-');
|
||||
|
||||
// Pretty-print the detailed error for now
|
||||
ProposalResponse::Rejected(format!("{kind}: {error:#?}"))
|
||||
}
|
||||
|
||||
/// Return a rejected response containing just the detailed error information.
|
||||
pub fn error(error: BoxError) -> Self {
|
||||
// Pretty-print the detailed error for now
|
||||
ProposalResponse::Rejected(format!("{error:#?}"))
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Error + Send + Sync + 'static> From<E> for ProposalResponse {
|
||||
fn from(error: E) -> Self {
|
||||
Self::error(error.into())
|
||||
ProposalResponse::Rejected(final_error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
source: zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs
|
||||
expression: block_template
|
||||
---
|
||||
"invalid proposal format: Io(\n Error {\n kind: UnexpectedEof,\n message: \"failed to fill whole buffer\",\n },\n)"
|
||||
"io-error-kind-unexpectedeof-message-failed-to-fill-whole-buffer"
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
source: zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs
|
||||
expression: block_template
|
||||
---
|
||||
"invalid proposal format: Io(\n Error {\n kind: UnexpectedEof,\n message: \"failed to fill whole buffer\",\n },\n)"
|
||||
"io-error-kind-unexpectedeof-message-failed-to-fill-whole-buffer"
|
||||
|
|
Loading…
Reference in New Issue