Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Place StatusExt and RpcStatusExt into separate files. #1662

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 1 addition & 6 deletions tonic-types/src/lib.rs
Expand Up @@ -182,12 +182,7 @@ pub mod pb {
pub use pb::Status;

mod richer_error;

pub use richer_error::{
BadRequest, DebugInfo, ErrorDetail, ErrorDetails, ErrorInfo, FieldViolation, Help, HelpLink,
LocalizedMessage, PreconditionFailure, PreconditionViolation, QuotaFailure, QuotaViolation,
RequestInfo, ResourceInfo, RetryInfo, RpcStatusExt, StatusExt,
};
pub use richer_error::*;

mod sealed {
pub trait Sealed {}
Expand Down
10 changes: 3 additions & 7 deletions tonic-types/src/richer_error/error_details/mod.rs
@@ -1,12 +1,8 @@
use std::{collections::HashMap, time};
pub(super) mod vec;

use super::std_messages::{
BadRequest, DebugInfo, ErrorInfo, FieldViolation, Help, HelpLink, LocalizedMessage,
PreconditionFailure, PreconditionViolation, QuotaFailure, QuotaViolation, RequestInfo,
ResourceInfo, RetryInfo,
};
use std::{collections::HashMap, time};

pub(crate) mod vec;
use super::std_messages::*;

/// Groups the standard error messages structs. Provides associated
/// functions and methods to setup and edit each error message independently.
Expand Down
5 changes: 1 addition & 4 deletions tonic-types/src/richer_error/error_details/vec.rs
@@ -1,7 +1,4 @@
use super::super::std_messages::{
BadRequest, DebugInfo, ErrorInfo, Help, LocalizedMessage, PreconditionFailure, QuotaFailure,
RequestInfo, ResourceInfo, RetryInfo,
};
use super::super::std_messages::*;

/// Wraps the structs corresponding to the standard error messages, allowing
/// the implementation and handling of vectors containing any of them.
Expand Down
40 changes: 40 additions & 0 deletions tonic-types/src/richer_error/helpers.rs
@@ -0,0 +1,40 @@
use prost::{
bytes::{Bytes, BytesMut},
DecodeError, Message,
};
use prost_types::Any;
use tonic::Code;

use crate::pb;

pub(super) trait IntoAny {
fn into_any(self) -> Any;
}

#[allow(dead_code)]
pub(super) trait FromAny {
fn from_any(any: Any) -> Result<Self, DecodeError>
where
Self: Sized;
}

pub(super) trait FromAnyRef {
fn from_any_ref(any: &Any) -> Result<Self, DecodeError>
where
Self: Sized;
}

pub(super) fn gen_details_bytes(code: Code, message: &str, details: Vec<Any>) -> Bytes {
let status = pb::Status {
code: code as i32,
message: message.to_owned(),
details,
};

let mut buf = BytesMut::with_capacity(status.encoded_len());

// Should never panic since `buf` is initialized with sufficient capacity
status.encode(&mut buf).unwrap();

buf.freeze()
}