Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWhiteWu committed Feb 19, 2024
1 parent 1cfe7bb commit 54c7e22
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 7,455 deletions.
685 changes: 0 additions & 685 deletions pilota-build/test_data/thrift/default_value.rs.bak

This file was deleted.

2,521 changes: 0 additions & 2,521 deletions pilota-build/test_data/thrift/normal.rs.bak

This file was deleted.

4,185 changes: 0 additions & 4,185 deletions pilota-build/test_data/unknown_fields.rs.bak

This file was deleted.

32 changes: 7 additions & 25 deletions pilota/src/thrift/error/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use std::{
use faststr::FastStr;

use super::ThriftException;
use crate::thrift::{
use crate::{msg_impl, thrift::{
Message, TAsyncInputProtocol, TInputProtocol, TLengthProtocol, TOutputProtocol,
TStructIdentifier, TType,
};
}};

// use super::{DecodeError, EncodeError};

Expand Down Expand Up @@ -63,25 +63,7 @@ impl ApplicationException {
&self.message
}

/// Append a message to the existing error message.
///
/// That means, the new message will be: `old_message` + `message`.
pub fn append_msg(&mut self, message: &str) {
let mut s = String::with_capacity(self.message.len() + message.len());
s.push_str(self.message.as_str());
s.push_str(message);
self.message = s.into();
}

/// Prepend a message to the existing error message.
///
/// That means, the new message will be: `message` + `old_message`.
pub fn prepend_msg(&mut self, message: &str) {
let mut s = String::with_capacity(self.message.len() + message.len());
s.push_str(message);
s.push_str(self.message.as_str());
self.message = s.into();
}
msg_impl!();
}

impl Display for ApplicationException {
Expand All @@ -101,7 +83,7 @@ impl Display for ApplicationException {
_ => "other error",
};

write!(f, "{}, msg: {}", error_text, self.message)
write!(f, "{}: {}", error_text, self.message)
}
}

Expand Down Expand Up @@ -264,12 +246,12 @@ impl ApplicationExceptionKind {
pub const PROTOCOL_ERROR: Self = Self(7);
/// *Unknown*. Included only for compatibility with existing Thrift
/// implementations.
pub const INVALID_TRANSFORM: Self = Self(8); // ??
pub const INVALID_TRANSFORM: Self = Self(8);
/// Thrift endpoint requested, or is using, an unsupported encoding.
pub const INVALID_PROTOCOL: Self = Self(9); // ??
pub const INVALID_PROTOCOL: Self = Self(9);
/// Thrift endpoint requested, or is using, an unsupported auto-generated
/// client type.
pub const UNSUPPORTED_CLIENT_TYPE: Self = Self(10); // ??
pub const UNSUPPORTED_CLIENT_TYPE: Self = Self(10);
/// validation failed
pub const VALIDATION_FAILED: Self = Self(11);

Expand Down
25 changes: 25 additions & 0 deletions pilota/src/thrift/error/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#[doc(hidden)]
#[macro_export]
macro_rules! msg_impl {
() => {
/// Append a message to the existing error message.
///
/// That means, the new message will be: `old_message` + `message`.
pub fn append_msg(&mut self, message: &str) {
let mut s = String::with_capacity(self.message.len() + message.len());
s.push_str(self.message.as_str());
s.push_str(message);
self.message = s.into();
}

/// Prepend a message to the existing error message.
///
/// That means, the new message will be: `message` + `old_message`.
pub fn prepend_msg(&mut self, message: &str) {
let mut s = String::with_capacity(self.message.len() + message.len());
s.push_str(message);
s.push_str(self.message.as_str());
self.message = s.into();
}
};
}
1 change: 1 addition & 0 deletions pilota/src/thrift/error/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod application;
mod macros;
mod protocol;
mod transport;

Expand Down
24 changes: 4 additions & 20 deletions pilota/src/thrift/error/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::fmt::{self, Display, Formatter};

use faststr::FastStr;

use crate::msg_impl;

#[deprecated(
since = "0.11.0",
note = "Please use the `ProtocolException` instead. This type will be removed in the next release."
Expand Down Expand Up @@ -44,25 +46,7 @@ impl ProtocolException {
&self.message
}

/// Append a message to the existing error message.
///
/// That means, the new message will be: `old_message` + `message`.
pub fn append_msg(&mut self, message: &str) {
let mut s = String::with_capacity(self.message.len() + message.len());
s.push_str(self.message.as_str());
s.push_str(message);
self.message = s.into();
}

/// Prepend a message to the existing error message.
///
/// That means, the new message will be: `message` + `old_message`.
pub fn prepend_msg(&mut self, message: &str) {
let mut s = String::with_capacity(self.message.len() + message.len());
s.push_str(message);
s.push_str(self.message.as_str());
self.message = s.into();
}
msg_impl!();
}

impl Display for ProtocolException {
Expand All @@ -77,7 +61,7 @@ impl Display for ProtocolException {
ProtocolExceptionKind::DepthLimit => "maximum skip depth reached",
};

write!(f, "{}, {}", error_text, self.message)
write!(f, "{}: {}", error_text, self.message)
}
}

Expand Down
22 changes: 3 additions & 19 deletions pilota/src/thrift/error/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::{

use faststr::FastStr;

use crate::msg_impl;

#[deprecated(
since = "0.11.0",
note = "Please use the `TransportException` instead. This type will be removed in the next release."
Expand Down Expand Up @@ -50,25 +52,7 @@ impl TransportException {
self.io_error.kind()
}

/// Append a message to the existing error message.
///
/// That means, the new message will be: `old_message` + `message`.
pub fn append_msg(&mut self, message: &str) {
let mut s = String::with_capacity(self.message.len() + message.len());
s.push_str(self.message.as_str());
s.push_str(message);
self.message = s.into();
}

/// Prepend a message to the existing error message.
///
/// That means, the new message will be: `message` + `old_message`.
pub fn prepend_msg(&mut self, message: &str) {
let mut s = String::with_capacity(self.message.len() + message.len());
s.push_str(message);
s.push_str(self.message.as_str());
self.message = s.into();
}
msg_impl!();
}

impl From<io::Error> for TransportException {
Expand Down

0 comments on commit 54c7e22

Please sign in to comment.