From 902145df2967165d215568774f73a0fed6606981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Houl=C3=A9?= Date: Mon, 24 Feb 2020 12:05:24 +0100 Subject: [PATCH] Improve messages when cert/identity files are not found On postgres. --- src/connector/postgres.rs | 16 ++++++++++++++-- src/error.rs | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/connector/postgres.rs b/src/connector/postgres.rs index 32ab7f97b..4d909c333 100644 --- a/src/connector/postgres.rs +++ b/src/connector/postgres.rs @@ -101,12 +101,23 @@ impl SslParams { auth.accept_mode(self.ssl_accept_mode); if let Some(ref cert_file) = self.certificate_file { - let cert = fs::read(cert_file)?; + let cert = fs::read(cert_file).map_err(|err| { + Error::builder(ErrorKind::TlsError { + message: format!("cert file not found ({})", err), + }) + .build() + })?; + auth.certificate(Certificate::from_pem(&cert)?); } if let Some(ref identity_file) = self.identity_file { - let db = fs::read(identity_file)?; + let db = fs::read(identity_file).map_err(|err| { + Error::builder(ErrorKind::TlsError { + message: format!("identity file not found ({})", err), + }) + .build() + })?; let password = self.identity_password.0.as_ref().map(|s| s.as_str()).unwrap_or(""); let identity = Identity::from_pkcs12(&db, &password)?; @@ -347,6 +358,7 @@ impl PostgreSql { /// Create a new connection to the database. pub async fn new(url: PostgresUrl) -> crate::Result { let config = url.to_config(); + let mut tls_builder = TlsConnector::builder(); { diff --git a/src/error.rs b/src/error.rs index d06ae707d..0f60b3d10 100644 --- a/src/error.rs +++ b/src/error.rs @@ -138,7 +138,7 @@ pub enum ErrorKind { #[error("The provided arguments are not supported")] InvalidConnectionArguments, - #[error("Error in an I/O operation")] + #[error("Error in an I/O operation: {0}")] IoError(io::Error), #[error("Connect timed out ({0})")]