@@ -24,8 +24,7 @@ use rocketmq_common::common::message::MessageTrait;
24
24
use rocketmq_common:: common:: topic:: TopicValidator ;
25
25
use rocketmq_remoting:: code:: response_code:: ResponseCode ;
26
26
27
- use crate :: client_error:: ClientErr ;
28
- use crate :: client_error:: MQClientError :: MQClientErr ;
27
+ use crate :: mq_client_err;
29
28
use crate :: producer:: default_mq_producer:: ProducerConfig ;
30
29
use crate :: Result ;
31
30
@@ -37,21 +36,19 @@ impl Validators {
37
36
38
37
pub fn check_group ( group : & str ) -> Result < ( ) > {
39
38
if group. trim ( ) . is_empty ( ) {
40
- return Err ( MQClientErr ( ClientErr :: new ( "the specified group is blank" ) ) ) ;
39
+ return mq_client_err ! ( "the specified group is blank" ) ;
41
40
}
42
41
43
42
if group. len ( ) > Self :: CHARACTER_MAX_LENGTH {
44
- return Err ( MQClientErr ( ClientErr :: new (
45
- "the specified group is longer than group max length 255." ,
46
- ) ) ) ;
43
+ return mq_client_err ! ( "the specified group is longer than group max length 255." ) ;
47
44
}
48
45
49
46
if TopicValidator :: is_topic_or_group_illegal ( group) {
50
- return Err ( MQClientErr ( ClientErr :: new ( format ! (
47
+ return mq_client_err ! ( format!(
51
48
"the specified group[{}] contains illegal characters, allowing only \
52
49
^[%|a-zA-Z0-9_-]+$",
53
50
group
54
- ) ) ) ) ;
51
+ ) ) ;
55
52
}
56
53
Ok ( ( ) )
57
54
}
@@ -61,53 +58,53 @@ impl Validators {
61
58
M : MessageTrait ,
62
59
{
63
60
if msg. is_none ( ) {
64
- return Err ( MQClientErr ( ClientErr :: new_with_code (
61
+ return mq_client_err ! (
65
62
ResponseCode :: MessageIllegal as i32 ,
66
- "the message is null" . to_string ( ) ,
67
- ) ) ) ;
63
+ "the message is null" . to_string( )
64
+ ) ;
68
65
}
69
66
let msg = msg. unwrap ( ) ;
70
67
Self :: check_topic ( msg. get_topic ( ) ) ?;
71
68
Self :: is_not_allowed_send_topic ( msg. get_topic ( ) ) ?;
72
69
73
70
if msg. get_body ( ) . is_none ( ) {
74
- return Err ( MQClientErr ( ClientErr :: new_with_code (
71
+ return mq_client_err ! (
75
72
ResponseCode :: MessageIllegal as i32 ,
76
- "the message body is null" . to_string ( ) ,
77
- ) ) ) ;
73
+ "the message body is null" . to_string( )
74
+ ) ;
78
75
}
79
76
80
77
let length = msg. get_body ( ) . unwrap ( ) . len ( ) ;
81
78
if length == 0 {
82
- return Err ( MQClientErr ( ClientErr :: new_with_code (
79
+ return mq_client_err ! (
83
80
ResponseCode :: MessageIllegal as i32 ,
84
- "the message body length is zero" . to_string ( ) ,
85
- ) ) ) ;
81
+ "the message body length is zero" . to_string( )
82
+ ) ;
86
83
}
87
84
88
85
if length > producer_config. max_message_size ( ) as usize {
89
- return Err ( MQClientErr ( ClientErr :: new_with_code (
86
+ return mq_client_err ! (
90
87
ResponseCode :: MessageIllegal as i32 ,
91
88
format!(
92
89
"the message body size over max value, MAX: {}" ,
93
90
producer_config. max_message_size( )
94
- ) ,
95
- ) ) ) ;
91
+ )
92
+ ) ;
96
93
}
97
94
98
95
let lmq_path = msg. get_user_property ( & CheetahString :: from_static_str (
99
96
MessageConst :: PROPERTY_INNER_MULTI_DISPATCH ,
100
97
) ) ;
101
98
if let Some ( value) = lmq_path {
102
99
if value. contains ( std:: path:: MAIN_SEPARATOR ) {
103
- return Err ( MQClientErr ( ClientErr :: new_with_code (
100
+ return mq_client_err ! (
104
101
ResponseCode :: MessageIllegal as i32 ,
105
102
format!(
106
103
"INNER_MULTI_DISPATCH {} can not contains {} character" ,
107
104
value,
108
105
std:: path:: MAIN_SEPARATOR
109
- ) ,
110
- ) ) ) ;
106
+ )
107
+ ) ;
111
108
}
112
109
}
113
110
@@ -116,54 +113,51 @@ impl Validators {
116
113
117
114
pub fn check_topic ( topic : & str ) -> Result < ( ) > {
118
115
if topic. trim ( ) . is_empty ( ) {
119
- return Err ( MQClientErr ( ClientErr :: new ( "The specified topic is blank" ) ) ) ;
116
+ return mq_client_err ! ( "The specified topic is blank" ) ;
120
117
}
121
118
122
119
if topic. len ( ) > Self :: TOPIC_MAX_LENGTH {
123
- return Err ( MQClientErr ( ClientErr :: new ( format ! (
120
+ return mq_client_err ! ( format!(
124
121
"The specified topic is longer than topic max length {}." ,
125
122
Self :: TOPIC_MAX_LENGTH
126
- ) ) ) ) ;
123
+ ) ) ;
127
124
}
128
125
129
126
if TopicValidator :: is_topic_or_group_illegal ( topic) {
130
- return Err ( MQClientErr ( ClientErr :: new ( format ! (
127
+ return mq_client_err ! ( format!(
131
128
"The specified topic[{}] contains illegal characters, allowing only \
132
129
^[%|a-zA-Z0-9_-]+$",
133
130
topic
134
- ) ) ) ) ;
131
+ ) ) ;
135
132
}
136
133
137
134
Ok ( ( ) )
138
135
}
139
136
140
137
pub fn is_system_topic ( topic : & str ) -> Result < ( ) > {
141
138
if TopicValidator :: is_system_topic ( topic) {
142
- return Err ( MQClientErr ( ClientErr :: new ( format ! (
139
+ return mq_client_err ! ( format!(
143
140
"The topic[{}] is conflict with system topic." ,
144
141
topic
145
- ) ) ) ) ;
142
+ ) ) ;
146
143
}
147
144
Ok ( ( ) )
148
145
}
149
146
150
147
pub fn is_not_allowed_send_topic ( topic : & str ) -> Result < ( ) > {
151
148
if TopicValidator :: is_not_allowed_send_topic ( topic) {
152
- return Err ( MQClientErr ( ClientErr :: new ( format ! (
153
- "Sending message to topic[{}] is forbidden." ,
154
- topic
155
- ) ) ) ) ;
149
+ return mq_client_err ! ( format!( "Sending message to topic[{}] is forbidden." , topic) ) ;
156
150
}
157
151
158
152
Ok ( ( ) )
159
153
}
160
154
161
155
pub fn check_topic_config ( topic_config : & TopicConfig ) -> Result < ( ) > {
162
156
if !PermName :: is_valid ( topic_config. perm ) {
163
- return Err ( MQClientErr ( ClientErr :: new_with_code (
157
+ return mq_client_err ! (
164
158
ResponseCode :: NoPermission as i32 ,
165
- format ! ( "topicPermission value: {} is invalid." , topic_config. perm) ,
166
- ) ) ) ;
159
+ format!( "topicPermission value: {} is invalid." , topic_config. perm)
160
+ ) ;
167
161
}
168
162
169
163
Ok ( ( ) )
@@ -172,10 +166,10 @@ impl Validators {
172
166
pub fn check_broker_config ( broker_config : & HashMap < String , String > ) -> Result < ( ) > {
173
167
if let Some ( broker_permission) = broker_config. get ( "brokerPermission" ) {
174
168
if !PermName :: is_valid ( broker_permission. parse ( ) . unwrap ( ) ) {
175
- return Err ( MQClientErr ( ClientErr :: new ( format ! (
169
+ return mq_client_err ! ( format!(
176
170
"brokerPermission value: {} is invalid." ,
177
171
broker_permission
178
- ) ) ) ) ;
172
+ ) ) ;
179
173
}
180
174
}
181
175
0 commit comments