@@ -329,9 +329,9 @@ macro_rules! scenario {
329
329
} ;
330
330
}
331
331
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
333
333
/// [`TransactionError`](./enum.TransactionError.html) on error.
334
- pub type TransactionResult = Result < ( ) , TransactionError > ;
334
+ pub type TransactionResult = Result < ( ) , Box < TransactionError > > ;
335
335
336
336
/// An enumeration of all errors a [`Transaction`](./struct.Transaction.html) can return.
337
337
#[ derive( Debug ) ]
@@ -688,7 +688,7 @@ impl fmt::Display for GooseMethod {
688
688
689
689
/// Convert [`http::method::Method`](https://docs.rs/http/*/http/method/struct.Method.html)
690
690
/// 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 > > {
692
692
Ok ( match method {
693
693
Method :: DELETE => GooseMethod :: Delete ,
694
694
Method :: GET => GooseMethod :: Get ,
@@ -697,7 +697,7 @@ pub fn goose_method_from_method(method: Method) -> Result<GooseMethod, Transacti
697
697
Method :: POST => GooseMethod :: Post ,
698
698
Method :: PUT => GooseMethod :: Put ,
699
699
_ => {
700
- return Err ( TransactionError :: InvalidMethod { method } ) ;
700
+ return Err ( Box :: new ( TransactionError :: InvalidMethod { method } ) ) ;
701
701
}
702
702
} )
703
703
}
@@ -1087,7 +1087,7 @@ impl GooseUser {
1087
1087
/// current scenario)
1088
1088
/// 3. [`GooseDefault::Host`](../config/enum.GooseDefault.html#variant.Host) (default host
1089
1089
/// 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 > > {
1091
1091
// If URL includes a host, simply use it.
1092
1092
if let Ok ( parsed_path) = Url :: parse ( path) {
1093
1093
if let Some ( _host) = parsed_path. host ( ) {
@@ -1096,7 +1096,10 @@ impl GooseUser {
1096
1096
}
1097
1097
1098
1098
// 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
+ }
1100
1103
}
1101
1104
1102
1105
/// A helper to make a `GET` request of a path and collect relevant metrics.
@@ -1124,7 +1127,7 @@ impl GooseUser {
1124
1127
/// Ok(())
1125
1128
/// }
1126
1129
/// ```
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 > > {
1128
1131
// GET path.
1129
1132
let goose_request = GooseRequest :: builder ( )
1130
1133
. method ( GooseMethod :: Get )
@@ -1164,7 +1167,7 @@ impl GooseUser {
1164
1167
& mut self ,
1165
1168
path : & str ,
1166
1169
name : & str ,
1167
- ) -> Result < GooseResponse , TransactionError > {
1170
+ ) -> Result < GooseResponse , Box < TransactionError > > {
1168
1171
// GET path named.
1169
1172
let goose_request = GooseRequest :: builder ( )
1170
1173
. method ( GooseMethod :: Get )
@@ -1205,7 +1208,7 @@ impl GooseUser {
1205
1208
& mut self ,
1206
1209
path : & str ,
1207
1210
body : T ,
1208
- ) -> Result < GooseResponse , TransactionError > {
1211
+ ) -> Result < GooseResponse , Box < TransactionError > > {
1209
1212
// Build a Reqwest RequestBuilder object.
1210
1213
let url = self . build_url ( path) ?;
1211
1214
let reqwest_request_builder = self . client . post ( url) ;
@@ -1251,7 +1254,7 @@ impl GooseUser {
1251
1254
& mut self ,
1252
1255
path : & str ,
1253
1256
form : & T ,
1254
- ) -> Result < GooseResponse , TransactionError > {
1257
+ ) -> Result < GooseResponse , Box < TransactionError > > {
1255
1258
// Build a Reqwest RequestBuilder object.
1256
1259
let url = self . build_url ( path) ?;
1257
1260
let reqwest_request_builder = self . client . post ( url) ;
@@ -1300,7 +1303,7 @@ impl GooseUser {
1300
1303
& mut self ,
1301
1304
path : & str ,
1302
1305
json : & T ,
1303
- ) -> Result < GooseResponse , TransactionError > {
1306
+ ) -> Result < GooseResponse , Box < TransactionError > > {
1304
1307
// Build a Reqwest RequestBuilder object.
1305
1308
let url = self . build_url ( path) ?;
1306
1309
let reqwest_request_builder = self . client . post ( url) ;
@@ -1341,7 +1344,7 @@ impl GooseUser {
1341
1344
/// Ok(())
1342
1345
/// }
1343
1346
/// ```
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 > > {
1345
1348
// HEAD request.
1346
1349
let goose_request = GooseRequest :: builder ( )
1347
1350
. method ( GooseMethod :: Head )
@@ -1377,7 +1380,7 @@ impl GooseUser {
1377
1380
/// Ok(())
1378
1381
/// }
1379
1382
/// ```
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 > > {
1381
1384
// DELETE request.
1382
1385
let goose_request = GooseRequest :: builder ( )
1383
1386
. method ( GooseMethod :: Delete )
@@ -1433,7 +1436,7 @@ impl GooseUser {
1433
1436
& self ,
1434
1437
method : & GooseMethod ,
1435
1438
path : & str ,
1436
- ) -> Result < RequestBuilder , TransactionError > {
1439
+ ) -> Result < RequestBuilder , Box < TransactionError > > {
1437
1440
// Prepend the `base_url` to all relative paths.
1438
1441
let url = self . build_url ( path) ?;
1439
1442
@@ -1485,7 +1488,7 @@ impl GooseUser {
1485
1488
pub async fn request < ' a > (
1486
1489
& mut self ,
1487
1490
mut request : GooseRequest < ' _ > ,
1488
- ) -> Result < GooseResponse , TransactionError > {
1491
+ ) -> Result < GooseResponse , Box < TransactionError > > {
1489
1492
// If the RequestBuilder is already defined in the GooseRequest use it.
1490
1493
let request_builder = if request. request_builder . is_some ( ) {
1491
1494
request. request_builder . take ( ) . unwrap ( )
@@ -1502,14 +1505,19 @@ impl GooseUser {
1502
1505
// ...wait until there's room to add a token to the throttle channel before proceeding.
1503
1506
debug ! ( "GooseUser: waiting on throttle" ) ;
1504
1507
// 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
+ }
1506
1511
} ;
1507
1512
1508
1513
// Once past the throttle, the request is officially started.
1509
1514
let started = Instant :: now ( ) ;
1510
1515
1511
1516
// 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
+ } ;
1513
1521
1514
1522
// Get a string version of request path for logging.
1515
1523
let path = match Url :: parse ( built_request. url ( ) . as_ref ( ) ) {
@@ -1589,7 +1597,10 @@ impl GooseUser {
1589
1597
let base_url = self . base_url . to_string ( ) ;
1590
1598
// Check if the URL redirected started with the load test base_url.
1591
1599
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
+ } ;
1593
1604
let redirected_base_url =
1594
1605
redirected_url[ ..url:: Position :: BeforePath ] . to_string ( ) ;
1595
1606
info ! (
@@ -1627,9 +1638,9 @@ impl GooseUser {
1627
1638
1628
1639
if request. error_on_fail && !request_metric. success {
1629
1640
error ! ( "{:?} {}" , & path, & request_metric. error) ;
1630
- return Err ( TransactionError :: RequestFailed {
1641
+ return Err ( Box :: new ( TransactionError :: RequestFailed {
1631
1642
raw_request : request_metric,
1632
- } ) ;
1643
+ } ) ) ;
1633
1644
}
1634
1645
1635
1646
Ok ( GooseResponse :: new ( request_metric, response) )
@@ -1728,7 +1739,7 @@ impl GooseUser {
1728
1739
async fn coordinated_omission_mitigation (
1729
1740
& self ,
1730
1741
request_metric : & GooseRequestMetric ,
1731
- ) -> Result < u64 , TransactionError > {
1742
+ ) -> Result < u64 , Box < TransactionError > > {
1732
1743
if let Some ( co_mitigation) = self . config . co_mitigation . as_ref ( ) {
1733
1744
// Return immediately if coordinated omission mitigation is disabled.
1734
1745
if co_mitigation == & GooseCoordinatedOmissionMitigation :: Disabled {
@@ -1785,15 +1796,19 @@ impl GooseUser {
1785
1796
// If requests-file is enabled, send a copy of the raw request to the logger thread.
1786
1797
if !self . config . request_log . is_empty ( ) {
1787
1798
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
+ }
1789
1802
}
1790
1803
}
1791
1804
1792
1805
// Parent is not defined when running
1793
1806
// [`test_start`](../struct.GooseAttack.html#method.test_start),
1794
1807
// [`test_stop`](../struct.GooseAttack.html#method.test_stop), and during testing.
1795
1808
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
+ }
1797
1812
}
1798
1813
1799
1814
Ok ( ( ) )
@@ -1844,9 +1859,9 @@ impl GooseUser {
1844
1859
/// }
1845
1860
/// }
1846
1861
///
1847
- /// Err(TransactionError::RequestFailed {
1862
+ /// Err(Box::new( TransactionError::RequestFailed {
1848
1863
/// raw_request: goose.request.clone(),
1849
- /// })
1864
+ /// }))
1850
1865
/// }
1851
1866
/// ````
1852
1867
pub fn set_success ( & self , request : & mut GooseRequestMetric ) -> TransactionResult {
@@ -1934,9 +1949,9 @@ impl GooseUser {
1934
1949
// Print log to stdout.
1935
1950
info ! ( "set_failure: {}" , tag) ;
1936
1951
1937
- Err ( TransactionError :: RequestFailed {
1952
+ Err ( Box :: new ( TransactionError :: RequestFailed {
1938
1953
raw_request : request. clone ( ) ,
1939
- } )
1954
+ } ) )
1940
1955
}
1941
1956
1942
1957
/// Write to [`debug_file`](../struct.GooseConfiguration.html#structfield.debug_file)
@@ -2025,13 +2040,15 @@ impl GooseUser {
2025
2040
// [`test_stop`](../struct.GooseAttack.html#method.test_stop), and during testing.
2026
2041
if let Some ( logger) = self . logger . clone ( ) {
2027
2042
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 (
2029
2044
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 ( ) ) ) ;
2035
2052
}
2036
2053
}
2037
2054
}
@@ -2261,8 +2278,11 @@ impl GooseUser {
2261
2278
/// Ok(())
2262
2279
/// }
2263
2280
/// ```
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
+ } ;
2266
2286
Ok ( ( ) )
2267
2287
}
2268
2288
}
0 commit comments