Browse Source

fix: add error context

Yujia Qiao 4 years ago
parent
commit
1d5ad9c185
1 changed files with 5 additions and 2 deletions
  1. 5 2
      src/transport/tls.rs

+ 5 - 2
src/transport/tls.rs

@@ -32,8 +32,11 @@ impl Transport for TlsTransport {
 
         let connector = match config.trusted_root.as_ref() {
             Some(path) => {
-                let s = fs::read_to_string(path).await?;
-                let cert = Certificate::from_pem(s.as_bytes())?;
+                let s = fs::read_to_string(path)
+                    .await
+                    .with_context(|| "Failed to read the `tls.trusted_root`")?;
+                let cert = Certificate::from_pem(s.as_bytes())
+                    .with_context(|| "Failed to read certificate from `tls.trusted_root`")?;
                 let connector = native_tls::TlsConnector::builder()
                     .add_root_certificate(cert)
                     .build()?;