From f9e20322f7a715a1600bc3ba53dd4a80d5063bab Mon Sep 17 00:00:00 2001 From: diehuxx Date: Tue, 17 Sep 2024 14:49:16 -0400 Subject: [PATCH] Add context to error message and update test --- crates/web5/src/credentials/create.rs | 7 ++++--- .../src/credentials/verifiable_credential_1_1.rs | 5 +++-- crates/web5/src/http.rs | 12 ++++++++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/crates/web5/src/credentials/create.rs b/crates/web5/src/credentials/create.rs index 53c0c0d1..5f21e48a 100644 --- a/crates/web5/src/credentials/create.rs +++ b/crates/web5/src/credentials/create.rs @@ -641,9 +641,10 @@ mod tests { match result { Err(Web5Error::Network(err_msg)) => { assert!( - err_msg.contains("failed to lookup address information"), - "Error message is: {}", err_msg - ) + err_msg.contains("failed to connect to host"), + "Error message is: {}", + err_msg + ) } _ => panic!( "expected Web5Error::Network with specific message but got {:?}", diff --git a/crates/web5/src/credentials/verifiable_credential_1_1.rs b/crates/web5/src/credentials/verifiable_credential_1_1.rs index 491cbbe5..6b2dd02e 100644 --- a/crates/web5/src/credentials/verifiable_credential_1_1.rs +++ b/crates/web5/src/credentials/verifiable_credential_1_1.rs @@ -771,8 +771,9 @@ mod tests { match result { Err(Web5Error::Network(err_msg)) => { assert!( - err_msg.contains("failed to lookup address information"), - "Error message is: {}", err_msg + err_msg.contains("failed to connect to host"), + "Error message is: {}", + err_msg ) } _ => panic!( diff --git a/crates/web5/src/http.rs b/crates/web5/src/http.rs index 87d8567e..b059d59e 100644 --- a/crates/web5/src/http.rs +++ b/crates/web5/src/http.rs @@ -67,8 +67,10 @@ fn transmit(destination: &Destination, request: &[u8]) -> Result> { let rc_config = Arc::new(config); // Arc allows sharing the config // Make the TCP connection to the server - let stream = TcpStream::connect((&destination.host[..], destination.port)) - .map_err(|err| Web5Error::Network(err.to_string()))?; + let stream = + TcpStream::connect((&destination.host[..], destination.port)).map_err(|err| { + Web5Error::Network(format!("failed to connect to host: {}", err)) + })?; // Convert the server name to the expected type for TLS validation let server_name = ServerName::try_from(destination.host.clone()) @@ -90,8 +92,10 @@ fn transmit(destination: &Destination, request: &[u8]) -> Result> { .map_err(|err| Web5Error::Network(err.to_string()))?; } else { // HTTP connection - let mut stream = TcpStream::connect((&destination.host[..], destination.port)) - .map_err(|err| Web5Error::Network(err.to_string()))?; + let mut stream = + TcpStream::connect((&destination.host[..], destination.port)).map_err(|err| { + Web5Error::Network(format!("failed to connect to host: {}", err)) + })?; stream .write_all(request)