Skip to content

Commit c44ab3d

Browse files
committed
Place StatusExt and RpcStatusExt into separate files.
Also does some minor module imports cleanup. The goal is to make room for a `CodeExt` trait.
1 parent eeb3268 commit c44ab3d

18 files changed

+1103
-1109
lines changed

tonic-types/src/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,7 @@ pub mod pb {
182182
pub use pb::Status;
183183

184184
mod richer_error;
185-
186-
pub use richer_error::{
187-
BadRequest, DebugInfo, ErrorDetail, ErrorDetails, ErrorInfo, FieldViolation, Help, HelpLink,
188-
LocalizedMessage, PreconditionFailure, PreconditionViolation, QuotaFailure, QuotaViolation,
189-
RequestInfo, ResourceInfo, RetryInfo, RpcStatusExt, StatusExt,
190-
};
185+
pub use richer_error::*;
191186

192187
mod sealed {
193188
pub trait Sealed {}

tonic-types/src/richer_error/error_details/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
use std::{collections::HashMap, time};
1+
pub(super) mod vec;
22

3-
use super::std_messages::{
4-
BadRequest, DebugInfo, ErrorInfo, FieldViolation, Help, HelpLink, LocalizedMessage,
5-
PreconditionFailure, PreconditionViolation, QuotaFailure, QuotaViolation, RequestInfo,
6-
ResourceInfo, RetryInfo,
7-
};
3+
use std::{collections::HashMap, time};
84

9-
pub(crate) mod vec;
5+
use super::std_messages::*;
106

117
/// Groups the standard error messages structs. Provides associated
128
/// functions and methods to setup and edit each error message independently.

tonic-types/src/richer_error/error_details/vec.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use super::super::std_messages::{
2-
BadRequest, DebugInfo, ErrorInfo, Help, LocalizedMessage, PreconditionFailure, QuotaFailure,
3-
RequestInfo, ResourceInfo, RetryInfo,
4-
};
1+
use super::super::std_messages::*;
52

63
/// Wraps the structs corresponding to the standard error messages, allowing
74
/// the implementation and handling of vectors containing any of them.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use prost::{
2+
bytes::{Bytes, BytesMut},
3+
DecodeError, Message,
4+
};
5+
use prost_types::Any;
6+
use tonic::Code;
7+
8+
use crate::pb;
9+
10+
pub(super) trait IntoAny {
11+
fn into_any(self) -> Any;
12+
}
13+
14+
#[allow(dead_code)]
15+
pub(super) trait FromAny {
16+
fn from_any(any: Any) -> Result<Self, DecodeError>
17+
where
18+
Self: Sized;
19+
}
20+
21+
pub(super) trait FromAnyRef {
22+
fn from_any_ref(any: &Any) -> Result<Self, DecodeError>
23+
where
24+
Self: Sized;
25+
}
26+
27+
pub(super) fn gen_details_bytes(code: Code, message: &str, details: Vec<Any>) -> Bytes {
28+
let status = pb::Status {
29+
code: code as i32,
30+
message: message.to_owned(),
31+
details,
32+
};
33+
34+
let mut buf = BytesMut::with_capacity(status.encoded_len());
35+
36+
// Should never panic since `buf` is initialized with sufficient capacity
37+
status.encode(&mut buf).unwrap();
38+
39+
buf.freeze()
40+
}

0 commit comments

Comments
 (0)