mirror of
https://github.com/postgresml/pgcat.git
synced 2026-03-27 10:46:30 +00:00
Can pass config path as argument (#36)
* show better errors for config parsing * lint
This commit is contained in:
@@ -172,7 +172,7 @@ pub async fn parse(path: &str) -> Result<(), Error> {
|
|||||||
let mut file = match File::open(path).await {
|
let mut file = match File::open(path).await {
|
||||||
Ok(file) => file,
|
Ok(file) => file,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("{:?}", err);
|
error!("Could not open '{}': {}", path, err.to_string());
|
||||||
return Err(Error::BadConfig);
|
return Err(Error::BadConfig);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -180,7 +180,7 @@ pub async fn parse(path: &str) -> Result<(), Error> {
|
|||||||
match file.read_to_string(&mut contents).await {
|
match file.read_to_string(&mut contents).await {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("{:?}", err);
|
error!("Could not read config file: {}", err.to_string());
|
||||||
return Err(Error::BadConfig);
|
return Err(Error::BadConfig);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -188,7 +188,7 @@ pub async fn parse(path: &str) -> Result<(), Error> {
|
|||||||
let config: Config = match toml::from_str(&contents) {
|
let config: Config = match toml::from_str(&contents) {
|
||||||
Ok(config) => config,
|
Ok(config) => config,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("{:?}", err);
|
error!("Could not parse config file: {}", err.to_string());
|
||||||
return Err(Error::BadConfig);
|
return Err(Error::BadConfig);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -200,6 +200,17 @@ pub async fn parse(path: &str) -> Result<(), Error> {
|
|||||||
let mut dup_check = HashSet::new();
|
let mut dup_check = HashSet::new();
|
||||||
let mut primary_count = 0;
|
let mut primary_count = 0;
|
||||||
|
|
||||||
|
match shard.0.parse::<usize>() {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(_) => {
|
||||||
|
error!(
|
||||||
|
"Shard '{}' is not a valid number, shards must be numbered starting at 0",
|
||||||
|
shard.0
|
||||||
|
);
|
||||||
|
return Err(Error::BadConfig);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if shard.1.servers.len() == 0 {
|
if shard.1.servers.len() == 0 {
|
||||||
error!("Shard {} has no servers configured", shard.0);
|
error!("Shard {} has no servers configured", shard.0);
|
||||||
return Err(Error::BadConfig);
|
return Err(Error::BadConfig);
|
||||||
|
|||||||
10
src/main.rs
10
src/main.rs
@@ -75,8 +75,16 @@ async fn main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let args = std::env::args().collect::<Vec<String>>();
|
||||||
|
|
||||||
|
let config_file = if args.len() == 2 {
|
||||||
|
args[1].to_string()
|
||||||
|
} else {
|
||||||
|
String::from("pgcat.toml")
|
||||||
|
};
|
||||||
|
|
||||||
// Prepare the config
|
// Prepare the config
|
||||||
match config::parse("pgcat.toml").await {
|
match config::parse(&config_file).await {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("Config parse error: {:?}", err);
|
error!("Config parse error: {:?}", err);
|
||||||
|
|||||||
Reference in New Issue
Block a user