Skip to content

Commit

Permalink
Revert "impl From<ErrorDetails> for Vec<Any>: (#1661)"
Browse files Browse the repository at this point in the history
This reverts commit a8c2022.
  • Loading branch information
LucioFranco committed Jun 19, 2024
1 parent a8c2022 commit a2ca892
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 49 deletions.
48 changes: 0 additions & 48 deletions tonic-types/src/richer_error/error_details/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,51 +880,3 @@ impl ErrorDetails {
self
}
}

impl From<ErrorDetails> for Vec<Any> {
fn from(details: ErrorDetails) -> Self {
let mut any_vec: Vec<Any> = Vec::with_capacity(10);

if let Some(retry_info) = details.retry_info {
any_vec.push(retry_info.into_any());
}

if let Some(debug_info) = details.debug_info {
any_vec.push(debug_info.into_any());
}

if let Some(quota_failure) = details.quota_failure {
any_vec.push(quota_failure.into_any());
}

if let Some(error_info) = details.error_info {
any_vec.push(error_info.into_any());
}

if let Some(precondition_failure) = details.precondition_failure {
any_vec.push(precondition_failure.into_any());
}

if let Some(bad_request) = details.bad_request {
any_vec.push(bad_request.into_any());
}

if let Some(request_info) = details.request_info {
any_vec.push(request_info.into_any());
}

if let Some(resource_info) = details.resource_info {
any_vec.push(resource_info.into_any());
}

if let Some(help) = details.help {
any_vec.push(help.into_any());
}

if let Some(localized_message) = details.localized_message {
any_vec.push(localized_message.into_any());
}

any_vec
}
}
45 changes: 44 additions & 1 deletion tonic-types/src/richer_error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ trait IntoAny {
fn into_any(self) -> Any;
}

#[allow(dead_code)]
trait FromAny {
fn from_any(any: Any) -> Result<Self, DecodeError>
where
Expand Down Expand Up @@ -488,7 +489,49 @@ impl StatusExt for tonic::Status {
) -> Self {
let message: String = message.into();

let details = gen_details_bytes(code, &message, details.into());
let mut conv_details: Vec<Any> = Vec::with_capacity(10);

if let Some(retry_info) = details.retry_info {
conv_details.push(retry_info.into_any());
}

if let Some(debug_info) = details.debug_info {
conv_details.push(debug_info.into_any());
}

if let Some(quota_failure) = details.quota_failure {
conv_details.push(quota_failure.into_any());
}

if let Some(error_info) = details.error_info {
conv_details.push(error_info.into_any());
}

if let Some(precondition_failure) = details.precondition_failure {
conv_details.push(precondition_failure.into_any());
}

if let Some(bad_request) = details.bad_request {
conv_details.push(bad_request.into_any());
}

if let Some(request_info) = details.request_info {
conv_details.push(request_info.into_any());
}

if let Some(resource_info) = details.resource_info {
conv_details.push(resource_info.into_any());
}

if let Some(help) = details.help {
conv_details.push(help.into_any());
}

if let Some(localized_message) = details.localized_message {
conv_details.push(localized_message.into_any());
}

let details = gen_details_bytes(code, &message, conv_details);

tonic::Status::with_details_and_metadata(code, message, details, metadata)
}
Expand Down

0 comments on commit a2ca892

Please sign in to comment.