pub struct ErrorDetails {
    pub retry_info: Option<RetryInfo>,
    pub debug_info: Option<DebugInfo>,
    pub quota_failure: Option<QuotaFailure>,
    pub error_info: Option<ErrorInfo>,
    pub precondition_failure: Option<PreconditionFailure>,
    pub bad_request: Option<BadRequest>,
    pub request_info: Option<RequestInfo>,
    pub resource_info: Option<ResourceInfo>,
    pub help: Option<Help>,
    pub localized_message: Option<LocalizedMessage>,
}
Expand description

Groups the standard error messages structs. Provides associated functions and methods to setup and edit each error message independently. Used when extracting error details from tonic::Status, and when creating a tonic::Status with error details.

Fields§

§retry_info: Option<RetryInfo>

This field stores RetryInfo data, if any.

§debug_info: Option<DebugInfo>

This field stores DebugInfo data, if any.

§quota_failure: Option<QuotaFailure>

This field stores QuotaFailure data, if any.

§error_info: Option<ErrorInfo>

This field stores ErrorInfo data, if any.

§precondition_failure: Option<PreconditionFailure>

This field stores PreconditionFailure data, if any.

§bad_request: Option<BadRequest>

This field stores BadRequest data, if any.

§request_info: Option<RequestInfo>

This field stores RequestInfo data, if any.

§resource_info: Option<ResourceInfo>

This field stores ResourceInfo data, if any.

§help: Option<Help>

This field stores Help data, if any.

§localized_message: Option<LocalizedMessage>

This field stores LocalizedMessage data, if any.

Implementations§

source§

impl ErrorDetails

source

pub fn new() -> Self

Generates an ErrorDetails struct with all fields set to None.

Examples
use tonic_richer_error::{ErrorDetails};

let err_details = ErrorDetails::new();
source

pub fn with_retry_info(retry_delay: Option<Duration>) -> Self

Generates an ErrorDetails struct with RetryInfo details and remaining fields set to None.

Examples
use std::time::Duration;
use tonic_richer_error::{ErrorDetails};

let err_details = ErrorDetails::with_retry_info(Some(Duration::from_secs(5)));
source

pub fn with_debug_info( stack_entries: Vec<String>, detail: impl Into<String> ) -> Self

Generates an ErrorDetails struct with DebugInfo details and remaining fields set to None.

Examples
use tonic_richer_error::{ErrorDetails};

let err_stack = vec!["...".into(), "...".into()];

let err_details = ErrorDetails::with_debug_info(err_stack, "error details");
source

pub fn with_quota_failure(violations: Vec<QuotaViolation>) -> Self

Generates an ErrorDetails struct with QuotaFailure details and remaining fields set to None.

Examples
use tonic_richer_error::{ErrorDetails, QuotaViolation};

let err_details = ErrorDetails::with_quota_failure(vec![
    QuotaViolation::new("subject 1", "description 1"),
    QuotaViolation::new("subject 2", "description 2"),
]);
source

pub fn with_quota_failure_violation( subject: impl Into<String>, description: impl Into<String> ) -> Self

Generates an ErrorDetails struct with QuotaFailure details (one QuotaViolation set) and remaining fields set to None.

Examples
use tonic_richer_error::{ErrorDetails};

let err_details = ErrorDetails::with_quota_failure_violation("subject", "description");
source

pub fn with_error_info( reason: impl Into<String>, domain: impl Into<String>, metadata: HashMap<String, String> ) -> Self

Generates an ErrorDetails struct with ErrorInfo details and remaining fields set to None.

Examples
use std::collections::HashMap;
use tonic_richer_error::{ErrorDetails};

let mut metadata: HashMap<String, String> = HashMap::new();
metadata.insert("instanceLimitPerRequest".into(), "100".into());

let err_details = ErrorDetails::with_error_info("reason", "domain", metadata);
source

pub fn with_precondition_failure(violations: Vec<PreconditionViolation>) -> Self

Generates an ErrorDetails struct with PreconditionFailure details and remaining fields set to None.

Examples
use tonic_richer_error::{ErrorDetails, PreconditionViolation};

let err_details = ErrorDetails::with_precondition_failure(vec![
    PreconditionViolation::new(
        "violation type 1",
        "subject 1",
        "description 1",
    ),
    PreconditionViolation::new(
        "violation type 2",
        "subject 2",
        "description 2",
    ),
]);
source

pub fn with_precondition_failure_violation( violation_type: impl Into<String>, subject: impl Into<String>, description: impl Into<String> ) -> Self

Generates an ErrorDetails struct with PreconditionFailure details (one PreconditionViolation set) and remaining fields set to None.

Examples
use tonic_richer_error::{ErrorDetails};

let err_details = ErrorDetails::with_precondition_failure_violation(
    "violation type",
    "subject",
    "description",
);
source

pub fn with_bad_request(field_violations: Vec<FieldViolation>) -> Self

Generates an ErrorDetails struct with BadRequest details and remaining fields set to None.

Examples
use tonic_richer_error::{ErrorDetails, FieldViolation};

let err_details = ErrorDetails::with_bad_request(vec![
    FieldViolation::new("field_1", "description 1"),
    FieldViolation::new("field_2", "description 2"),
]);
source

pub fn with_bad_request_violation( field: impl Into<String>, description: impl Into<String> ) -> Self

Generates an ErrorDetails struct with BadRequest details (one FieldViolation set) and remaining fields set to None.

Examples
use tonic_richer_error::{ErrorDetails};

let err_details = ErrorDetails::with_bad_request_violation(
    "field",
    "description",
);
source

pub fn with_request_info( request_id: impl Into<String>, serving_data: impl Into<String> ) -> Self

Generates an ErrorDetails struct with RequestInfo details and remaining fields set to None.

Examples
use tonic_richer_error::{ErrorDetails};

let err_details = ErrorDetails::with_request_info(
    "request_id",
    "serving_data",
);
source

pub fn with_resource_info( resource_type: impl Into<String>, resource_name: impl Into<String>, owner: impl Into<String>, description: impl Into<String> ) -> Self

Generates an ErrorDetails struct with ResourceInfo details and remaining fields set to None.

Examples
use tonic_richer_error::{ErrorDetails};

let err_details = ErrorDetails::with_resource_info(
    "res_type",
    "res_name",
    "owner",
    "description",
);
source

pub fn with_help(links: Vec<HelpLink>) -> Self

Generates an ErrorDetails struct with Help details and remaining fields set to None.

Examples
use tonic_richer_error::{ErrorDetails, HelpLink};

let err_details = ErrorDetails::with_help(vec![
    HelpLink::new("description of link a", "resource-a.example.local"),
    HelpLink::new("description of link b", "resource-b.example.local"),
]);

Generates an ErrorDetails struct with Help details (one HelpLink set) and remaining fields set to None.

Examples
use tonic_richer_error::{ErrorDetails};

let err_details = ErrorDetails::with_help_link(
    "description of link a",
    "resource-a.example.local"
);
source

pub fn with_localized_message( locale: impl Into<String>, message: impl Into<String> ) -> Self

Generates an ErrorDetails struct with LocalizedMessage details and remaining fields set to None.

Examples
use tonic_richer_error::{ErrorDetails};

let err_details = ErrorDetails::with_localized_message(
    "en-US",
    "message for the user"
);
source§

impl ErrorDetails

source

pub fn set_retry_info(&mut self, retry_delay: Option<Duration>) -> &mut Self

Set RetryInfo details. Can be chained with other .set_ and .add_ ErrorDetails methods.

Examples
use std::time::Duration;
use tonic_richer_error::{ErrorDetails};

let mut err_details = ErrorDetails::new();

err_details.set_retry_info(Some(Duration::from_secs(5)));
source

pub fn set_debug_info( &mut self, stack_entries: Vec<String>, detail: impl Into<String> ) -> &mut Self

Set DebugInfo details. Can be chained with other .set_ and .add_ ErrorDetails methods.

Examples
use tonic_richer_error::{ErrorDetails};

let mut err_details = ErrorDetails::new();

let err_stack = vec!["...".into(), "...".into()];

err_details.set_debug_info(err_stack, "error details");
source

pub fn set_quota_failure( &mut self, violations: Vec<QuotaViolation> ) -> &mut Self

Set QuotaFailure details. Can be chained with other .set_ and .add_ ErrorDetails methods.

Examples
use tonic_richer_error::{ErrorDetails, QuotaViolation};

let mut err_details = ErrorDetails::new();

err_details.set_quota_failure(vec![
    QuotaViolation::new("subject 1", "description 1"),
    QuotaViolation::new("subject 2", "description 2"),
]);
source

pub fn add_quota_failure_violation( &mut self, subject: impl Into<String>, description: impl Into<String> ) -> &mut Self

Adds a QuotaViolation to QuotaFailure details. Sets QuotaFailure details if it is not set yet. Can be chained with other .set_ and .add_ ErrorDetails methods.

Examples
use tonic_richer_error::{ErrorDetails};

let mut err_details = ErrorDetails::new();

err_details.add_quota_failure_violation("subject", "description");
source

pub fn has_quota_failure_violations(&self) -> bool

Returns true if QuotaFailure is set and its violations vector is not empty, otherwise returns false.

Examples
use tonic_richer_error::{ErrorDetails};

let mut err_details = ErrorDetails::with_quota_failure(vec![]);

assert_eq!(err_details.has_quota_failure_violations(), false);

err_details.add_quota_failure_violation("subject", "description");

assert_eq!(err_details.has_quota_failure_violations(), true);
source

pub fn set_error_info( &mut self, reason: impl Into<String>, domain: impl Into<String>, metadata: HashMap<String, String> ) -> &mut Self

Set ErrorInfo details. Can be chained with other .set_ and .add_ ErrorDetails methods.

Examples
use std::collections::HashMap;
use tonic_richer_error::{ErrorDetails};

let mut err_details = ErrorDetails::new();

let mut metadata: HashMap<String, String> = HashMap::new();
metadata.insert("instanceLimitPerRequest".into(), "100".into());

err_details.set_error_info("reason", "example.local", metadata);
source

pub fn set_precondition_failure( &mut self, violations: Vec<PreconditionViolation> ) -> &mut Self

Set PreconditionFailure details. Can be chained with other .set_ and .add_ ErrorDetails methods.

Examples
use tonic_richer_error::{ErrorDetails, PreconditionViolation};

let mut err_details = ErrorDetails::new();

err_details.set_precondition_failure(vec![
    PreconditionViolation::new(
        "violation type 1",
        "subject 1",
        "description 1",
    ),
    PreconditionViolation::new(
        "violation type 2",
        "subject 2",
        "description 2",
    ),
]);
source

pub fn add_precondition_failure_violation( &mut self, violation_type: impl Into<String>, subject: impl Into<String>, description: impl Into<String> ) -> &mut Self

Adds a PreconditionViolation to PreconditionFailure details. Sets PreconditionFailure details if it is not set yet. Can be chained with other .set_ and .add_ ErrorDetails methods.

Examples
use tonic_richer_error::{ErrorDetails};

let mut err_details = ErrorDetails::new();

err_details.add_precondition_failure_violation(
    "violation type",
    "subject",
    "description"
);
source

pub fn has_precondition_failure_violations(&self) -> bool

Returns true if PreconditionFailure is set and its violations vector is not empty, otherwise returns false.

Examples
use tonic_richer_error::{ErrorDetails};

let mut err_details = ErrorDetails::with_precondition_failure(vec![]);

assert_eq!(err_details.has_precondition_failure_violations(), false);

err_details.add_precondition_failure_violation(
    "violation type",
    "subject",
    "description"
);

assert_eq!(err_details.has_precondition_failure_violations(), true);
source

pub fn set_bad_request(&mut self, violations: Vec<FieldViolation>) -> &mut Self

Set BadRequest details. Can be chained with other .set_ and .add_ ErrorDetails methods.

Examples
use tonic_richer_error::{ErrorDetails, FieldViolation};

let mut err_details = ErrorDetails::new();

err_details.set_bad_request(vec![
    FieldViolation::new("field_1", "description 1"),
    FieldViolation::new("field_2", "description 2"),
]);
source

pub fn add_bad_request_violation( &mut self, field: impl Into<String>, description: impl Into<String> ) -> &mut Self

Adds a FieldViolation to BadRequest details. Sets BadRequest details if it is not set yet. Can be chained with other .set_ and .add_ ErrorDetails methods.

Examples
use tonic_richer_error::{ErrorDetails};

let mut err_details = ErrorDetails::new();

err_details.add_bad_request_violation("field", "description");
source

pub fn has_bad_request_violations(&self) -> bool

Returns true if BadRequest is set and its field_violations vector is not empty, otherwise returns false.

Examples
use tonic_richer_error::{ErrorDetails};

let mut err_details = ErrorDetails::with_bad_request(vec![]);

assert_eq!(err_details.has_bad_request_violations(), false);

err_details.add_bad_request_violation("field", "description");

assert_eq!(err_details.has_bad_request_violations(), true);
source

pub fn set_request_info( &mut self, request_id: impl Into<String>, serving_data: impl Into<String> ) -> &mut Self

Set RequestInfo details. Can be chained with other .set_ and .add_ ErrorDetails methods.

Examples
use tonic_richer_error::{ErrorDetails};

let mut err_details = ErrorDetails::new();

err_details.set_request_info("request_id", "serving_data");
source

pub fn set_resource_info( &mut self, resource_type: impl Into<String>, resource_name: impl Into<String>, owner: impl Into<String>, description: impl Into<String> ) -> &mut Self

Set ResourceInfo details. Can be chained with other .set_ and .add_ ErrorDetails methods.

Examples
use tonic_richer_error::{ErrorDetails};

let mut err_details = ErrorDetails::new();

err_details.set_resource_info("res_type", "res_name", "owner", "description");
source

pub fn set_help(&mut self, links: Vec<HelpLink>) -> &mut Self

Set Help details. Can be chained with other .set_ and .add_ ErrorDetails methods.

Examples
use tonic_richer_error::{ErrorDetails, HelpLink};

let mut err_details = ErrorDetails::new();

err_details.set_help(vec![
    HelpLink::new("description of link a", "resource-a.example.local"),
    HelpLink::new("description of link b", "resource-b.example.local"),
]);

Adds a HelpLink to Help details. Sets Help details if it is not set yet. Can be chained with other .set_ and .add_ ErrorDetails methods.

Examples
use tonic_richer_error::{ErrorDetails};

let mut err_details = ErrorDetails::new();

err_details.add_help_link("description of link", "resource.example.local");

Returns true if Help is set and its links vector is not empty, otherwise returns false.

Examples
use tonic_richer_error::{ErrorDetails};

let mut err_details = ErrorDetails::with_help(vec![]);

assert_eq!(err_details.has_help_links(), false);

err_details.add_help_link("description of link", "resource.example.local");

assert_eq!(err_details.has_help_links(), true);
source

pub fn set_localized_message( &mut self, locale: impl Into<String>, message: impl Into<String> ) -> &mut Self

Set LocalizedMessage details. Can be chained with other .set_ and .add_ ErrorDetails methods.

Examples
use tonic_richer_error::{ErrorDetails};

let mut err_details = ErrorDetails::new();

err_details.set_localized_message("en-US", "message for the user");

Trait Implementations§

source§

impl Clone for ErrorDetails

source§

fn clone(&self) -> ErrorDetails

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ErrorDetails

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more