Skip to content

Commit 503ad2d

Browse files
committed
f constant-ify the err string
1 parent a768586 commit 503ad2d

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

lightning/src/routing/network_graph.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,8 +2434,7 @@ mod benches {
24342434

24352435
#[bench]
24362436
fn read_network_graph(bench: &mut Bencher) {
2437-
let mut d = ::routing::router::test_utils::get_route_file()
2438-
.expect("Please fetch https://bitcoin.ninja/ldk-net_graph-45d86ead641d-2021-05-27.bin and place it at lightning/net_graph-2021-05-27.bin");
2437+
let mut d = ::routing::router::test_utils::get_route_file().unwrap();
24392438
let mut v = Vec::new();
24402439
d.read_to_end(&mut v).unwrap();
24412440
bench.iter(|| {
@@ -2445,8 +2444,7 @@ mod benches {
24452444

24462445
#[bench]
24472446
fn write_network_graph(bench: &mut Bencher) {
2448-
let mut d = ::routing::router::test_utils::get_route_file()
2449-
.expect("Please fetch https://bitcoin.ninja/ldk-net_graph-45d86ead641d-2021-05-27.bin and place it at lightning/net_graph-2021-05-27.bin");
2447+
let mut d = ::routing::router::test_utils::get_route_file().unwrap();
24502448
let net_graph = NetworkGraph::read(&mut d).unwrap();
24512449
bench.iter(|| {
24522450
let _ = net_graph.encode();

lightning/src/routing/router.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3869,8 +3869,8 @@ mod tests {
38693869
fn generate_routes() {
38703870
let mut d = match super::test_utils::get_route_file() {
38713871
Ok(f) => f,
3872-
Err(_) => {
3873-
eprintln!("Please fetch https://bitcoin.ninja/ldk-net_graph-45d86ead641d-2021-05-27.bin and place it at lightning/net_graph-2021-05-27.bin");
3872+
Err(e) => {
3873+
eprintln!("{}", e);
38743874
return;
38753875
},
38763876
};
@@ -3896,8 +3896,8 @@ mod tests {
38963896
fn generate_routes_mpp() {
38973897
let mut d = match super::test_utils::get_route_file() {
38983898
Ok(f) => f,
3899-
Err(_) => {
3900-
eprintln!("Please fetch https://bitcoin.ninja/ldk-net_graph-45d86ead641d-2021-05-27.bin and place it at lightning/net_graph-2021-05-27.bin");
3899+
Err(e) => {
3900+
eprintln!("{}", e);
39013901
return;
39023902
},
39033903
};
@@ -3924,7 +3924,7 @@ mod tests {
39243924
pub(crate) mod test_utils {
39253925
use std::fs::File;
39263926
/// Tries to open a network graph file, or panics with a URL to fetch it.
3927-
pub(crate) fn get_route_file() -> Result<std::fs::File, std::io::Error> {
3927+
pub(crate) fn get_route_file() -> Result<std::fs::File, &'static str> {
39283928
let res = File::open("net_graph-2021-05-27.bin") // By default we're run in RL/lightning
39293929
.or_else(|_| File::open("lightning/net_graph-2021-05-27.bin")) // We may be run manually in RL/
39303930
.or_else(|_| { // Fall back to guessing based on the binary location
@@ -3938,9 +3938,10 @@ pub(crate) mod test_utils {
39383938
path.push("net_graph-2021-05-27.bin");
39393939
eprintln!("{}", path.to_str().unwrap());
39403940
File::open(path)
3941-
});
3941+
})
3942+
.map_err(|_| "Please fetch https://bitcoin.ninja/ldk-net_graph-45d86ead641d-2021-05-27.bin and place it at lightning/net_graph-2021-05-27.bin");
39423943
#[cfg(require_route_graph_test)]
3943-
return Ok(res.expect("Didn't have route graph and was configured to require it"));
3944+
return Ok(res.unwrap())
39443945
#[cfg(not(require_route_graph_test))]
39453946
return res;
39463947
}
@@ -3961,8 +3962,7 @@ mod benches {
39613962

39623963
#[bench]
39633964
fn generate_routes(bench: &mut Bencher) {
3964-
let mut d = test_utils::get_route_file()
3965-
.expect("Please fetch https://bitcoin.ninja/ldk-net_graph-45d86ead641d-2021-05-27.bin and place it at lightning/net_graph-2021-05-27.bin");
3965+
let mut d = test_utils::get_route_file().unwrap();
39663966
let graph = NetworkGraph::read(&mut d).unwrap();
39673967

39683968
// First, get 100 (source, destination) pairs for which route-getting actually succeeds...
@@ -3993,8 +3993,7 @@ mod benches {
39933993

39943994
#[bench]
39953995
fn generate_mpp_routes(bench: &mut Bencher) {
3996-
let mut d = test_utils::get_route_file()
3997-
.expect("Please fetch https://bitcoin.ninja/ldk-net_graph-45d86ead641d-2021-05-27.bin and place it at lightning/net_graph-2021-05-27.bin");
3996+
let mut d = test_utils::get_route_file().unwrap();
39983997
let graph = NetworkGraph::read(&mut d).unwrap();
39993998

40003999
// First, get 100 (source, destination) pairs for which route-getting actually succeeds...

0 commit comments

Comments
 (0)