Skip to content

Place StatusExt and RpcStatusExt into separate files. #1662

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

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions tonic-types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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 {}
10 changes: 3 additions & 7 deletions tonic-types/src/richer_error/error_details/mod.rs
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 1 addition & 4 deletions tonic-types/src/richer_error/error_details/vec.rs
Original file line number Diff line number Diff line change
@@ -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.
40 changes: 40 additions & 0 deletions tonic-types/src/richer_error/helpers.rs
Original file line number Diff line number Diff line change
@@ -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()
}
Loading