#[non_exhaustive]pub struct ErrorDetails { /* private fields */ }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.
Implementations§
Source§impl ErrorDetails
impl ErrorDetails
Sourcepub fn new() -> Self
pub fn new() -> Self
Generates an ErrorDetails struct with all fields set to None.
§Examples
use tonic_types::ErrorDetails;
let err_details = ErrorDetails::new();Sourcepub fn with_retry_info(retry_delay: Option<Duration>) -> Self
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_types::ErrorDetails;
let err_details = ErrorDetails::with_retry_info(Some(Duration::from_secs(5)));Sourcepub fn with_debug_info(
stack_entries: impl Into<Vec<String>>,
detail: impl Into<String>,
) -> Self
pub fn with_debug_info( stack_entries: impl Into<Vec<String>>, detail: impl Into<String>, ) -> Self
Generates an ErrorDetails struct with DebugInfo details and
remaining fields set to None.
§Examples
use tonic_types::ErrorDetails;
let err_stack = vec!["...".into(), "...".into()];
let err_details = ErrorDetails::with_debug_info(err_stack, "error details");Sourcepub fn with_quota_failure(violations: impl Into<Vec<QuotaViolation>>) -> Self
pub fn with_quota_failure(violations: impl Into<Vec<QuotaViolation>>) -> Self
Generates an ErrorDetails struct with QuotaFailure details and
remaining fields set to None.
§Examples
use tonic_types::{ErrorDetails, QuotaViolation};
let err_details = ErrorDetails::with_quota_failure(vec![
QuotaViolation::new("subject 1", "description 1"),
QuotaViolation::new("subject 2", "description 2"),
]);Sourcepub fn with_quota_failure_violation(
subject: impl Into<String>,
description: impl Into<String>,
) -> Self
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_types::ErrorDetails;
let err_details = ErrorDetails::with_quota_failure_violation("subject", "description");Sourcepub fn with_error_info(
reason: impl Into<String>,
domain: impl Into<String>,
metadata: impl Into<HashMap<String, String>>,
) -> Self
pub fn with_error_info( reason: impl Into<String>, domain: impl Into<String>, metadata: impl Into<HashMap<String, String>>, ) -> Self
Generates an ErrorDetails struct with ErrorInfo details and
remaining fields set to None.
§Examples
use std::collections::HashMap;
use tonic_types::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);Sourcepub fn with_precondition_failure(
violations: impl Into<Vec<PreconditionViolation>>,
) -> Self
pub fn with_precondition_failure( violations: impl Into<Vec<PreconditionViolation>>, ) -> Self
Generates an ErrorDetails struct with PreconditionFailure
details and remaining fields set to None.
§Examples
use tonic_types::{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",
),
]);Sourcepub fn with_precondition_failure_violation(
violation_type: impl Into<String>,
subject: impl Into<String>,
description: impl Into<String>,
) -> Self
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_types::ErrorDetails;
let err_details = ErrorDetails::with_precondition_failure_violation(
"violation type",
"subject",
"description",
);Sourcepub fn with_bad_request(
field_violations: impl Into<Vec<FieldViolation>>,
) -> Self
pub fn with_bad_request( field_violations: impl Into<Vec<FieldViolation>>, ) -> Self
Generates an ErrorDetails struct with BadRequest details and
remaining fields set to None.
§Examples
use tonic_types::{ErrorDetails, FieldViolation};
let err_details = ErrorDetails::with_bad_request(vec![
FieldViolation::new("field_1", "description 1"),
FieldViolation::new("field_2", "description 2"),
]);Sourcepub fn with_bad_request_violation(
field: impl Into<String>,
description: impl Into<String>,
) -> Self
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_types::ErrorDetails;
let err_details = ErrorDetails::with_bad_request_violation(
"field",
"description",
);Sourcepub fn with_request_info(
request_id: impl Into<String>,
serving_data: impl Into<String>,
) -> Self
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_types::ErrorDetails;
let err_details = ErrorDetails::with_request_info(
"request_id",
"serving_data",
);Sourcepub fn with_resource_info(
resource_type: impl Into<String>,
resource_name: impl Into<String>,
owner: impl Into<String>,
description: impl Into<String>,
) -> Self
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_types::ErrorDetails;
let err_details = ErrorDetails::with_resource_info(
"res_type",
"res_name",
"owner",
"description",
);Sourcepub fn with_help(links: impl Into<Vec<HelpLink>>) -> Self
pub fn with_help(links: impl Into<Vec<HelpLink>>) -> Self
Generates an ErrorDetails struct with Help details and
remaining fields set to None.
§Examples
use tonic_types::{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"),
]);Sourcepub fn with_help_link(
description: impl Into<String>,
url: impl Into<String>,
) -> Self
pub fn with_help_link( description: impl Into<String>, url: impl Into<String>, ) -> Self
Generates an ErrorDetails struct with Help details (one
HelpLink set) and remaining fields set to None.
§Examples
use tonic_types::ErrorDetails;
let err_details = ErrorDetails::with_help_link(
"description of link a",
"resource-a.example.local"
);Sourcepub fn with_localized_message(
locale: impl Into<String>,
message: impl Into<String>,
) -> Self
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_types::ErrorDetails;
let err_details = ErrorDetails::with_localized_message(
"en-US",
"message for the user"
);Sourcepub fn retry_info(&self) -> Option<&RetryInfo>
pub fn retry_info(&self) -> Option<&RetryInfo>
Get RetryInfo details, if any.
Sourcepub fn debug_info(&self) -> Option<&DebugInfo>
pub fn debug_info(&self) -> Option<&DebugInfo>
Get DebugInfo details, if any.
Sourcepub fn quota_failure(&self) -> Option<&QuotaFailure>
pub fn quota_failure(&self) -> Option<&QuotaFailure>
Get QuotaFailure details, if any.
Sourcepub fn error_info(&self) -> Option<&ErrorInfo>
pub fn error_info(&self) -> Option<&ErrorInfo>
Get ErrorInfo details, if any.
Sourcepub fn precondition_failure(&self) -> Option<&PreconditionFailure>
pub fn precondition_failure(&self) -> Option<&PreconditionFailure>
Get PreconditionFailure details, if any.
Sourcepub fn bad_request(&self) -> Option<&BadRequest>
pub fn bad_request(&self) -> Option<&BadRequest>
Get BadRequest details, if any.
Sourcepub fn request_info(&self) -> Option<&RequestInfo>
pub fn request_info(&self) -> Option<&RequestInfo>
Get RequestInfo details, if any.
Sourcepub fn resource_info(&self) -> Option<&ResourceInfo>
pub fn resource_info(&self) -> Option<&ResourceInfo>
Get ResourceInfo details, if any.
Sourcepub fn localized_message(&self) -> Option<&LocalizedMessage>
pub fn localized_message(&self) -> Option<&LocalizedMessage>
Get LocalizedMessage details, if any.
Sourcepub fn set_retry_info(&mut self, retry_delay: Option<Duration>) -> &mut Self
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_types::ErrorDetails;
let mut err_details = ErrorDetails::new();
err_details.set_retry_info(Some(Duration::from_secs(5)));Sourcepub fn set_debug_info(
&mut self,
stack_entries: impl Into<Vec<String>>,
detail: impl Into<String>,
) -> &mut Self
pub fn set_debug_info( &mut self, stack_entries: impl Into<Vec<String>>, detail: impl Into<String>, ) -> &mut Self
Set DebugInfo details. Can be chained with other .set_ and
.add_ ErrorDetails methods.
§Examples
use tonic_types::ErrorDetails;
let mut err_details = ErrorDetails::new();
let err_stack = vec!["...".into(), "...".into()];
err_details.set_debug_info(err_stack, "error details");Sourcepub fn set_quota_failure(
&mut self,
violations: impl Into<Vec<QuotaViolation>>,
) -> &mut Self
pub fn set_quota_failure( &mut self, violations: impl Into<Vec<QuotaViolation>>, ) -> &mut Self
Set QuotaFailure details. Can be chained with other .set_ and
.add_ ErrorDetails methods.
§Examples
use tonic_types::{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"),
]);Sourcepub fn add_quota_failure_violation(
&mut self,
subject: impl Into<String>,
description: impl Into<String>,
) -> &mut Self
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_types::ErrorDetails;
let mut err_details = ErrorDetails::new();
err_details.add_quota_failure_violation("subject", "description");Sourcepub fn has_quota_failure_violations(&self) -> bool
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_types::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);Sourcepub fn set_error_info(
&mut self,
reason: impl Into<String>,
domain: impl Into<String>,
metadata: impl Into<HashMap<String, String>>,
) -> &mut Self
pub fn set_error_info( &mut self, reason: impl Into<String>, domain: impl Into<String>, metadata: impl Into<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_types::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);Sourcepub fn set_precondition_failure(
&mut self,
violations: impl Into<Vec<PreconditionViolation>>,
) -> &mut Self
pub fn set_precondition_failure( &mut self, violations: impl Into<Vec<PreconditionViolation>>, ) -> &mut Self
Set PreconditionFailure details. Can be chained with other .set_
and .add_ ErrorDetails methods.
§Examples
use tonic_types::{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",
),
]);Sourcepub fn add_precondition_failure_violation(
&mut self,
violation_type: impl Into<String>,
subject: impl Into<String>,
description: impl Into<String>,
) -> &mut Self
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_types::ErrorDetails;
let mut err_details = ErrorDetails::new();
err_details.add_precondition_failure_violation(
"violation type",
"subject",
"description"
);Sourcepub fn has_precondition_failure_violations(&self) -> bool
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_types::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);Sourcepub fn set_bad_request(
&mut self,
violations: impl Into<Vec<FieldViolation>>,
) -> &mut Self
pub fn set_bad_request( &mut self, violations: impl Into<Vec<FieldViolation>>, ) -> &mut Self
Set BadRequest details. Can be chained with other .set_ and
.add_ ErrorDetails methods.
§Examples
use tonic_types::{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"),
]);Sourcepub fn add_bad_request_violation(
&mut self,
field: impl Into<String>,
description: impl Into<String>,
) -> &mut Self
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_types::ErrorDetails;
let mut err_details = ErrorDetails::new();
err_details.add_bad_request_violation("field", "description");Sourcepub fn has_bad_request_violations(&self) -> bool
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_types::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);Sourcepub fn set_request_info(
&mut self,
request_id: impl Into<String>,
serving_data: impl Into<String>,
) -> &mut Self
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_types::ErrorDetails;
let mut err_details = ErrorDetails::new();
err_details.set_request_info("request_id", "serving_data");Sourcepub 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
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_types::ErrorDetails;
let mut err_details = ErrorDetails::new();
err_details.set_resource_info("res_type", "res_name", "owner", "description");Sourcepub fn set_help(&mut self, links: impl Into<Vec<HelpLink>>) -> &mut Self
pub fn set_help(&mut self, links: impl Into<Vec<HelpLink>>) -> &mut Self
Set Help details. Can be chained with other .set_ and .add_
ErrorDetails methods.
§Examples
use tonic_types::{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"),
]);Sourcepub fn add_help_link(
&mut self,
description: impl Into<String>,
url: impl Into<String>,
) -> &mut Self
pub fn add_help_link( &mut self, description: impl Into<String>, url: impl Into<String>, ) -> &mut Self
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_types::ErrorDetails;
let mut err_details = ErrorDetails::new();
err_details.add_help_link("description of link", "resource.example.local");Sourcepub fn has_help_links(&self) -> bool
pub fn has_help_links(&self) -> bool
Returns true if Help is set and its links vector is not empty,
otherwise returns false.
§Examples
use tonic_types::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);Sourcepub fn set_localized_message(
&mut self,
locale: impl Into<String>,
message: impl Into<String>,
) -> &mut Self
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_types::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
impl Clone for ErrorDetails
Source§fn clone(&self) -> ErrorDetails
fn clone(&self) -> ErrorDetails
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ErrorDetails
impl Debug for ErrorDetails
Source§impl Default for ErrorDetails
impl Default for ErrorDetails
Source§fn default() -> ErrorDetails
fn default() -> ErrorDetails
Auto Trait Implementations§
impl Freeze for ErrorDetails
impl RefUnwindSafe for ErrorDetails
impl Send for ErrorDetails
impl Sync for ErrorDetails
impl Unpin for ErrorDetails
impl UnwindSafe for ErrorDetails
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request