Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Improve messages when cert/identity files are not found
Browse files Browse the repository at this point in the history
On postgres.
  • Loading branch information
tomhoule committed Feb 24, 2020
1 parent 001fcdd commit 902145d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/connector/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down Expand Up @@ -347,6 +358,7 @@ impl PostgreSql {
/// Create a new connection to the database.
pub async fn new(url: PostgresUrl) -> crate::Result<Self> {
let config = url.to_config();

let mut tls_builder = TlsConnector::builder();

{
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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})")]
Expand Down

0 comments on commit 902145d

Please sign in to comment.