Skip to content

Commit bfb3a60

Browse files
committed
clippy cleanups
1 parent 5b771ec commit bfb3a60

File tree

5 files changed

+63
-65
lines changed

5 files changed

+63
-65
lines changed

build.rs

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ impl GooseConfiguration {
13031303
message: "",
13041304
},
13051305
])
1306-
.unwrap_or_else(|| "".to_string());
1306+
.unwrap_or_default();
13071307

13081308
// Initialize the Goose logger.
13091309
self.initialize_goose_logger();

src/goose.rs

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,9 @@ macro_rules! scenario {
329329
};
330330
}
331331

332-
/// Goose transactions return a result, which is empty on success, or contains a
332+
/// Goose transactions return a result, which is empty on success, or contains a boxed
333333
/// [`TransactionError`](./enum.TransactionError.html) on error.
334-
pub type TransactionResult = Result<(), TransactionError>;
334+
pub type TransactionResult = Result<(), Box<TransactionError>>;
335335

336336
/// An enumeration of all errors a [`Transaction`](./struct.Transaction.html) can return.
337337
#[derive(Debug)]
@@ -688,7 +688,7 @@ impl fmt::Display for GooseMethod {
688688

689689
/// Convert [`http::method::Method`](https://docs.rs/http/*/http/method/struct.Method.html)
690690
/// to [`GooseMethod`](./enum.GooseMethod.html).
691-
pub fn goose_method_from_method(method: Method) -> Result<GooseMethod, TransactionError> {
691+
pub fn goose_method_from_method(method: Method) -> Result<GooseMethod, Box<TransactionError>> {
692692
Ok(match method {
693693
Method::DELETE => GooseMethod::Delete,
694694
Method::GET => GooseMethod::Get,
@@ -697,7 +697,7 @@ pub fn goose_method_from_method(method: Method) -> Result<GooseMethod, Transacti
697697
Method::POST => GooseMethod::Post,
698698
Method::PUT => GooseMethod::Put,
699699
_ => {
700-
return Err(TransactionError::InvalidMethod { method });
700+
return Err(Box::new(TransactionError::InvalidMethod { method }));
701701
}
702702
})
703703
}
@@ -1087,7 +1087,7 @@ impl GooseUser {
10871087
/// current scenario)
10881088
/// 3. [`GooseDefault::Host`](../config/enum.GooseDefault.html#variant.Host) (default host
10891089
/// defined for the current load test)
1090-
pub fn build_url(&self, path: &str) -> Result<String, TransactionError> {
1090+
pub fn build_url(&self, path: &str) -> Result<String, Box<TransactionError>> {
10911091
// If URL includes a host, simply use it.
10921092
if let Ok(parsed_path) = Url::parse(path) {
10931093
if let Some(_host) = parsed_path.host() {
@@ -1096,7 +1096,10 @@ impl GooseUser {
10961096
}
10971097

10981098
// Otherwise use the `base_url`.
1099-
Ok(self.base_url.join(path)?.to_string())
1099+
match self.base_url.join(path) {
1100+
Ok(u) => Ok(u.to_string()),
1101+
Err(e) => Err(Box::new(e.into())),
1102+
}
11001103
}
11011104

11021105
/// A helper to make a `GET` request of a path and collect relevant metrics.
@@ -1124,7 +1127,7 @@ impl GooseUser {
11241127
/// Ok(())
11251128
/// }
11261129
/// ```
1127-
pub async fn get(&mut self, path: &str) -> Result<GooseResponse, TransactionError> {
1130+
pub async fn get(&mut self, path: &str) -> Result<GooseResponse, Box<TransactionError>> {
11281131
// GET path.
11291132
let goose_request = GooseRequest::builder()
11301133
.method(GooseMethod::Get)
@@ -1164,7 +1167,7 @@ impl GooseUser {
11641167
&mut self,
11651168
path: &str,
11661169
name: &str,
1167-
) -> Result<GooseResponse, TransactionError> {
1170+
) -> Result<GooseResponse, Box<TransactionError>> {
11681171
// GET path named.
11691172
let goose_request = GooseRequest::builder()
11701173
.method(GooseMethod::Get)
@@ -1205,7 +1208,7 @@ impl GooseUser {
12051208
&mut self,
12061209
path: &str,
12071210
body: T,
1208-
) -> Result<GooseResponse, TransactionError> {
1211+
) -> Result<GooseResponse, Box<TransactionError>> {
12091212
// Build a Reqwest RequestBuilder object.
12101213
let url = self.build_url(path)?;
12111214
let reqwest_request_builder = self.client.post(url);
@@ -1251,7 +1254,7 @@ impl GooseUser {
12511254
&mut self,
12521255
path: &str,
12531256
form: &T,
1254-
) -> Result<GooseResponse, TransactionError> {
1257+
) -> Result<GooseResponse, Box<TransactionError>> {
12551258
// Build a Reqwest RequestBuilder object.
12561259
let url = self.build_url(path)?;
12571260
let reqwest_request_builder = self.client.post(url);
@@ -1300,7 +1303,7 @@ impl GooseUser {
13001303
&mut self,
13011304
path: &str,
13021305
json: &T,
1303-
) -> Result<GooseResponse, TransactionError> {
1306+
) -> Result<GooseResponse, Box<TransactionError>> {
13041307
// Build a Reqwest RequestBuilder object.
13051308
let url = self.build_url(path)?;
13061309
let reqwest_request_builder = self.client.post(url);
@@ -1341,7 +1344,7 @@ impl GooseUser {
13411344
/// Ok(())
13421345
/// }
13431346
/// ```
1344-
pub async fn head(&mut self, path: &str) -> Result<GooseResponse, TransactionError> {
1347+
pub async fn head(&mut self, path: &str) -> Result<GooseResponse, Box<TransactionError>> {
13451348
// HEAD request.
13461349
let goose_request = GooseRequest::builder()
13471350
.method(GooseMethod::Head)
@@ -1377,7 +1380,7 @@ impl GooseUser {
13771380
/// Ok(())
13781381
/// }
13791382
/// ```
1380-
pub async fn delete(&mut self, path: &str) -> Result<GooseResponse, TransactionError> {
1383+
pub async fn delete(&mut self, path: &str) -> Result<GooseResponse, Box<TransactionError>> {
13811384
// DELETE request.
13821385
let goose_request = GooseRequest::builder()
13831386
.method(GooseMethod::Delete)
@@ -1433,7 +1436,7 @@ impl GooseUser {
14331436
&self,
14341437
method: &GooseMethod,
14351438
path: &str,
1436-
) -> Result<RequestBuilder, TransactionError> {
1439+
) -> Result<RequestBuilder, Box<TransactionError>> {
14371440
// Prepend the `base_url` to all relative paths.
14381441
let url = self.build_url(path)?;
14391442

@@ -1485,7 +1488,7 @@ impl GooseUser {
14851488
pub async fn request<'a>(
14861489
&mut self,
14871490
mut request: GooseRequest<'_>,
1488-
) -> Result<GooseResponse, TransactionError> {
1491+
) -> Result<GooseResponse, Box<TransactionError>> {
14891492
// If the RequestBuilder is already defined in the GooseRequest use it.
14901493
let request_builder = if request.request_builder.is_some() {
14911494
request.request_builder.take().unwrap()
@@ -1502,14 +1505,19 @@ impl GooseUser {
15021505
// ...wait until there's room to add a token to the throttle channel before proceeding.
15031506
debug!("GooseUser: waiting on throttle");
15041507
// Will result in TransactionError::RequestCanceled if this fails.
1505-
self.throttle.clone().unwrap().send_async(true).await?;
1508+
if let Err(e) = self.throttle.clone().unwrap().send_async(true).await {
1509+
return Err(Box::new(e.into()));
1510+
}
15061511
};
15071512

15081513
// Once past the throttle, the request is officially started.
15091514
let started = Instant::now();
15101515

15111516
// Create a Reqwest Request object from the RequestBuilder.
1512-
let built_request = request_builder.build()?;
1517+
let built_request = match request_builder.build() {
1518+
Ok(r) => r,
1519+
Err(e) => return Err(Box::new(e.into())),
1520+
};
15131521

15141522
// Get a string version of request path for logging.
15151523
let path = match Url::parse(built_request.url().as_ref()) {
@@ -1589,7 +1597,10 @@ impl GooseUser {
15891597
let base_url = self.base_url.to_string();
15901598
// Check if the URL redirected started with the load test base_url.
15911599
if !request_metric.final_url.starts_with(&base_url) {
1592-
let redirected_url = Url::parse(&request_metric.final_url)?;
1600+
let redirected_url = match Url::parse(&request_metric.final_url) {
1601+
Ok(u) => u,
1602+
Err(e) => return Err(Box::new(e.into())),
1603+
};
15931604
let redirected_base_url =
15941605
redirected_url[..url::Position::BeforePath].to_string();
15951606
info!(
@@ -1627,9 +1638,9 @@ impl GooseUser {
16271638

16281639
if request.error_on_fail && !request_metric.success {
16291640
error!("{:?} {}", &path, &request_metric.error);
1630-
return Err(TransactionError::RequestFailed {
1641+
return Err(Box::new(TransactionError::RequestFailed {
16311642
raw_request: request_metric,
1632-
});
1643+
}));
16331644
}
16341645

16351646
Ok(GooseResponse::new(request_metric, response))
@@ -1728,7 +1739,7 @@ impl GooseUser {
17281739
async fn coordinated_omission_mitigation(
17291740
&self,
17301741
request_metric: &GooseRequestMetric,
1731-
) -> Result<u64, TransactionError> {
1742+
) -> Result<u64, Box<TransactionError>> {
17321743
if let Some(co_mitigation) = self.config.co_mitigation.as_ref() {
17331744
// Return immediately if coordinated omission mitigation is disabled.
17341745
if co_mitigation == &GooseCoordinatedOmissionMitigation::Disabled {
@@ -1785,15 +1796,19 @@ impl GooseUser {
17851796
// If requests-file is enabled, send a copy of the raw request to the logger thread.
17861797
if !self.config.request_log.is_empty() {
17871798
if let Some(logger) = self.logger.as_ref() {
1788-
logger.send(Some(GooseLog::Request(request_metric.clone())))?;
1799+
if let Err(e) = logger.send(Some(GooseLog::Request(request_metric.clone()))) {
1800+
return Err(Box::new(e.into()));
1801+
}
17891802
}
17901803
}
17911804

17921805
// Parent is not defined when running
17931806
// [`test_start`](../struct.GooseAttack.html#method.test_start),
17941807
// [`test_stop`](../struct.GooseAttack.html#method.test_stop), and during testing.
17951808
if let Some(metrics_channel) = self.metrics_channel.clone() {
1796-
metrics_channel.send(GooseMetric::Request(request_metric))?;
1809+
if let Err(e) = metrics_channel.send(GooseMetric::Request(request_metric)) {
1810+
return Err(Box::new(e.into()));
1811+
}
17971812
}
17981813

17991814
Ok(())
@@ -1844,9 +1859,9 @@ impl GooseUser {
18441859
/// }
18451860
/// }
18461861
///
1847-
/// Err(TransactionError::RequestFailed {
1862+
/// Err(Box::new(TransactionError::RequestFailed {
18481863
/// raw_request: goose.request.clone(),
1849-
/// })
1864+
/// }))
18501865
/// }
18511866
/// ````
18521867
pub fn set_success(&self, request: &mut GooseRequestMetric) -> TransactionResult {
@@ -1934,9 +1949,9 @@ impl GooseUser {
19341949
// Print log to stdout.
19351950
info!("set_failure: {}", tag);
19361951

1937-
Err(TransactionError::RequestFailed {
1952+
Err(Box::new(TransactionError::RequestFailed {
19381953
raw_request: request.clone(),
1939-
})
1954+
}))
19401955
}
19411956

19421957
/// Write to [`debug_file`](../struct.GooseConfiguration.html#structfield.debug_file)
@@ -2025,13 +2040,15 @@ impl GooseUser {
20252040
// [`test_stop`](../struct.GooseAttack.html#method.test_stop), and during testing.
20262041
if let Some(logger) = self.logger.clone() {
20272042
if self.config.no_debug_body {
2028-
logger.send(Some(GooseLog::Debug(GooseDebug::new(
2043+
if let Err(e) = logger.send(Some(GooseLog::Debug(GooseDebug::new(
20292044
tag, request, headers, None,
2030-
))))?;
2031-
} else {
2032-
logger.send(Some(GooseLog::Debug(GooseDebug::new(
2033-
tag, request, headers, body,
2034-
))))?;
2045+
)))) {
2046+
return Err(Box::new(e.into()));
2047+
}
2048+
} else if let Err(e) = logger.send(Some(GooseLog::Debug(GooseDebug::new(
2049+
tag, request, headers, body,
2050+
)))) {
2051+
return Err(Box::new(e.into()));
20352052
}
20362053
}
20372054
}
@@ -2261,8 +2278,11 @@ impl GooseUser {
22612278
/// Ok(())
22622279
/// }
22632280
/// ```
2264-
pub fn set_base_url(&mut self, host: &str) -> Result<(), TransactionError> {
2265-
self.base_url = Url::parse(host)?;
2281+
pub fn set_base_url(&mut self, host: &str) -> Result<(), Box<TransactionError>> {
2282+
self.base_url = match Url::parse(host) {
2283+
Ok(u) => u,
2284+
Err(e) => return Err(Box::new(e.into())),
2285+
};
22662286
Ok(())
22672287
}
22682288
}

src/logger.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl FromStr for GooseLogFormat {
212212
fn from_str(s: &str) -> Result<Self, Self::Err> {
213213
// Use a [`RegexSet`] to match string representations of `GooseCoordinatedOmissionMitigation`,
214214
// returning the appropriate enum value. Also match a wide range of abbreviations and synonyms.
215-
let log_format = RegexSet::new(&[
215+
let log_format = RegexSet::new([
216216
r"(?i)^csv$",
217217
r"(?i)^(json|jsn)$",
218218
r"(?i)^raw$",
@@ -483,7 +483,7 @@ impl GooseConfiguration {
483483
message: "",
484484
},
485485
])
486-
.unwrap_or_else(|| "".to_string());
486+
.unwrap_or_default();
487487

488488
// Set `debug_format`.
489489
self.debug_format = self.get_value(vec![
@@ -523,7 +523,7 @@ impl GooseConfiguration {
523523
message: "",
524524
},
525525
])
526-
.unwrap_or_else(|| "".to_string());
526+
.unwrap_or_default();
527527

528528
// Set `error_format`.
529529
self.error_format = self.get_value(vec![
@@ -563,7 +563,7 @@ impl GooseConfiguration {
563563
message: "",
564564
},
565565
])
566-
.unwrap_or_else(|| "".to_string());
566+
.unwrap_or_default();
567567

568568
// Set `request_format`.
569569
self.request_format = self.get_value(vec![
@@ -621,7 +621,7 @@ impl GooseConfiguration {
621621
message: "",
622622
},
623623
])
624-
.unwrap_or_else(|| "".to_string());
624+
.unwrap_or_default();
625625

626626
// Set `transaction_format`.
627627
self.transaction_format = self.get_value(vec![
@@ -661,7 +661,7 @@ impl GooseConfiguration {
661661
message: "",
662662
},
663663
])
664-
.unwrap_or_else(|| "".to_string());
664+
.unwrap_or_default();
665665

666666
// Set `scenario_format`.
667667
self.scenario_format = self.get_value(vec![

src/metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl FromStr for GooseCoordinatedOmissionMitigation {
8888
fn from_str(s: &str) -> Result<Self, Self::Err> {
8989
// Use a [`RegexSet`] to match string representations of `GooseCoordinatedOmissionMitigation`,
9090
// returning the appropriate enum value. Also match a wide range of abbreviations and synonyms.
91-
let co_mitigation = RegexSet::new(&[
91+
let co_mitigation = RegexSet::new([
9292
r"(?i)^(average|ave|aver|avg|mean)$",
9393
r"(?i)^(maximum|ma|max|maxi)$",
9494
r"(?i)^(minimum|mi|min|mini)$",

0 commit comments

Comments
 (0)