Skip to content

Commit

Permalink
feat: check and log the output of pg_dump --version
Browse files Browse the repository at this point in the history
  • Loading branch information
AlisaAkiron committed Mar 7, 2024
1 parent 44b69e3 commit 68c01a6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
7 changes: 3 additions & 4 deletions src/pg/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ pub async fn dump_database(

let output = cmd.output().await.expect("Failed to execute pg_dump");

if output.status.success() {
Ok(())
} else {
Err(output.status.code())
match output.status.success() {
true => Ok(()),
false => Err(output.status.code()),
}
}

Expand Down
34 changes: 24 additions & 10 deletions src/pg/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use tokio::process::Command;

use log::info;
use log::{error, info};

use crate::configs::PgDump;

Expand All @@ -14,15 +14,29 @@ pub async fn preflight_check(pg_dump: &PgDump) {
&pg_dump.binary_path
);

let status = Command::new(&pg_dump.binary_path)
let output = Command::new(&pg_dump.binary_path)
.arg("--version")
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::null())
.status()
.await;

match status {
Ok(_) => info!("Preflight check: pg_dump binary found and version is ok"),
Err(e) => panic!("Failed to run pg_dump --version: {}", e),
.output()
.await
.expect("Failed to execute pg_dump");

let mut output_vec = output.stdout;
output_vec.retain(|&c| c != 10 && c != 13);
let output_message = String::from_utf8(output_vec);

match output_message {
Ok(val) => info!("Preflight check: pg_dump output: {}", val),
Err(e) => error!("Preflight check: Failed to parse pg_dump output: {}", e),
};

match output.status.success() {
true => info!("Preflight check: pg_dump binary found and version is ok"),
false => {
let err_message = String::from_utf8(output.stderr).unwrap_or("unknwon".to_string());
panic!(
"Failed to run pg_dump --version with error: {}",
err_message
);
}
}
}

0 comments on commit 68c01a6

Please sign in to comment.