chore: Fix clippy lint (#1181)

This commit is contained in:
tottoto
2022-12-14 01:29:29 +09:00
committed by GitHub
parent 3076e8251e
commit 2dd09c02bd
23 changed files with 98 additions and 62 deletions
+15
View File
@@ -5,6 +5,7 @@
///
/// You can find out more about this error model and how to work with it in the
/// [API Design Guide](<https://cloud.google.com/apis/design/errors>).
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Status {
/// The status code, which should be an enum value of \\[google.rpc.Code\]\[google.rpc.Code\\].
@@ -33,6 +34,7 @@ pub struct Status {
/// the delay between retries based on `retry_delay`, until either a maximum
/// number of retries have been reached or a maximum retry delay cap has been
/// reached.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct RetryInfo {
/// Clients should wait at least this long between retrying the same request.
@@ -40,6 +42,7 @@ pub struct RetryInfo {
pub retry_delay: ::core::option::Option<::prost_types::Duration>,
}
/// Describes additional debugging info.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct DebugInfo {
/// The stack trace entries indicating where the error occurred.
@@ -60,6 +63,7 @@ pub struct DebugInfo {
///
/// Also see RetryInfo and Help types for other details about handling a
/// quota failure.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct QuotaFailure {
/// Describes all quota violations.
@@ -70,6 +74,7 @@ pub struct QuotaFailure {
pub mod quota_failure {
/// A message type used to describe a single quota violation. For example, a
/// daily quota or a custom quota that was exceeded.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Violation {
/// The subject on which the quota check failed.
@@ -116,6 +121,7 @@ pub mod quota_failure {
/// }
/// }
/// ```
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ErrorInfo {
/// The reason of the error. This is a constant value that identifies the
@@ -151,6 +157,7 @@ pub struct ErrorInfo {
/// For example, if an RPC failed because it required the Terms of Service to be
/// acknowledged, it could list the terms of service violation in the
/// PreconditionFailure message.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PreconditionFailure {
/// Describes all precondition violations.
@@ -160,6 +167,7 @@ pub struct PreconditionFailure {
/// Nested message and enum types in `PreconditionFailure`.
pub mod precondition_failure {
/// A message type used to describe a single precondition failure.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Violation {
/// The type of PreconditionFailure. We recommend using a service-specific
@@ -182,6 +190,7 @@ pub mod precondition_failure {
}
/// Describes violations in a client request. This error type focuses on the
/// syntactic aspects of the request.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct BadRequest {
/// Describes all violations in a client request.
@@ -191,6 +200,7 @@ pub struct BadRequest {
/// Nested message and enum types in `BadRequest`.
pub mod bad_request {
/// A message type used to describe a single bad request field.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct FieldViolation {
/// A path leading to a field in the request body. The value will be a
@@ -205,6 +215,7 @@ pub mod bad_request {
}
/// Contains metadata about the request that clients can attach when filing a bug
/// or providing other forms of feedback.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct RequestInfo {
/// An opaque string that should only be interpreted by the service generating
@@ -217,6 +228,7 @@ pub struct RequestInfo {
pub serving_data: ::prost::alloc::string::String,
}
/// Describes the resource that is being accessed.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ResourceInfo {
/// A name for the type of resource being accessed, e.g. "sql table",
@@ -245,6 +257,7 @@ pub struct ResourceInfo {
/// For example, if a quota check failed with an error indicating the calling
/// project hasn't enabled the accessed service, this can contain a URL pointing
/// directly to the right place in the developer console to flip the bit.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Help {
/// URL(s) pointing to additional information on handling the current error.
@@ -254,6 +267,7 @@ pub struct Help {
/// Nested message and enum types in `Help`.
pub mod help {
/// Describes a URL link.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Link {
/// Describes what the link offers.
@@ -266,6 +280,7 @@ pub mod help {
}
/// Provides a localized error message that is safe to return to the user
/// which can be attached to an RPC error.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct LocalizedMessage {
/// The locale used following the specification defined at
@@ -247,3 +247,9 @@ impl ErrorDetails {
false
}
}
impl Default for ErrorDetails {
fn default() -> Self {
Self::new()
}
}
+12 -16
View File
@@ -20,10 +20,10 @@ trait FromAny {
Self: Sized;
}
fn gen_details_bytes(code: Code, message: &String, details: Vec<Any>) -> Bytes {
fn gen_details_bytes(code: Code, message: &str, details: Vec<Any>) -> Bytes {
let status = pb::Status {
code: code as i32,
message: message.clone(),
message: message.to_owned(),
details,
};
@@ -411,7 +411,7 @@ impl StatusExt for tonic::Status {
}
fn get_error_details(&self) -> ErrorDetails {
self.check_error_details().unwrap_or(ErrorDetails::new())
self.check_error_details().unwrap_or_default()
}
fn check_error_details_vec(&self) -> Result<Vec<ErrorDetail>, DecodeError> {
@@ -438,19 +438,17 @@ impl StatusExt for tonic::Status {
}
fn get_error_details_vec(&self) -> Vec<ErrorDetail> {
self.check_error_details_vec().unwrap_or(Vec::new())
self.check_error_details_vec().unwrap_or_default()
}
fn get_details_retry_info(&self) -> Option<RetryInfo> {
let status = pb::Status::decode(self.details()).ok()?;
for any in status.details.into_iter() {
match any.type_url.as_str() {
RetryInfo::TYPE_URL => match RetryInfo::from_any(any) {
Ok(detail) => return Some(detail),
Err(_) => {}
},
_ => {}
if any.type_url.as_str() == RetryInfo::TYPE_URL {
if let Ok(detail) = RetryInfo::from_any(any) {
return Some(detail);
}
}
}
@@ -477,12 +475,10 @@ impl StatusExt for tonic::Status {
let status = pb::Status::decode(self.details()).ok()?;
for any in status.details.into_iter() {
match any.type_url.as_str() {
BadRequest::TYPE_URL => match BadRequest::from_any(any) {
Ok(detail) => return Some(detail),
Err(_) => {}
},
_ => {}
if any.type_url.as_str() == BadRequest::TYPE_URL {
if let Ok(detail) = BadRequest::from_any(any) {
return Some(detail);
}
}
}
@@ -153,7 +153,7 @@ mod tests {
);
assert!(
br_details.is_empty() == false,
!br_details.is_empty(),
"filled BadRequest returns 'true' from .is_empty()"
);
@@ -7,7 +7,7 @@ use super::super::{pb, FromAny, IntoAny};
/// Used to encode/decode the `RetryInfo` standard error message described in
/// [error_details.proto]. Describes when the clients can retry a failed
/// request.
/// request.
/// Note: When obtained from decoding `RetryInfo` messages, negative
/// `retry_delay`'s become 0.
///
@@ -119,7 +119,7 @@ mod tests {
);
assert!(
error_info.is_empty() == false,
!error_info.is_empty(),
"filled RetryInfo returns 'false' from .has_retry_delay()"
);