Skip to content

Commit

Permalink
[BGS-150] [messages] when router config doesn’t exist at the path pro…
Browse files Browse the repository at this point in the history
…vided in `--router-config`, stderr should receive message `{path} does not exist, creating a router config from CLI options.`
  • Loading branch information
monkpow committed Jan 9, 2025
1 parent 4a0b3b1 commit 6b4a740
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 43 deletions.
6 changes: 0 additions & 6 deletions src/command/dev/next/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ impl Dev {

let router_config_path = self.opts.supergraph_opts.router_config_path.clone();

let _config = RunRouterConfig::default()
.with_address(router_address)
.with_config(&read_file_impl, router_config_path.as_ref())
.await
.map_err(|err| RoverError::new(anyhow!("{}", err)))?;

let profile = &self.opts.plugin_opts.profile;
let graph_ref = &self.opts.supergraph_opts.graph_ref;
if let Some(graph_ref) = graph_ref {
Expand Down
78 changes: 41 additions & 37 deletions src/command/dev/next/router/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use buildstructor::buildstructor;
use camino::Utf8PathBuf;
use http::Uri;
use rover_std::errln;
use rover_std::{Fs, RoverStdError};
use thiserror::Error;

Expand Down Expand Up @@ -130,44 +131,47 @@ impl RunRouterConfig<RunRouterConfigReadConfig> {
path: Option<&Utf8PathBuf>,
) -> Result<RunRouterConfig<RunRouterConfigFinal>, ReadRouterConfigError> {
match path {
Some(path) => {
Fs::assert_path_exists(&path).map_err(ReadRouterConfigError::Fs)?;

match read_file_impl.read_file(&path).await {
Ok(contents) => {
let yaml = serde_yaml::from_str(&contents).map_err(|err| {
ReadRouterConfigError::Deserialization {
path: path.clone(),
source: err,
}
})?;

let router_config = RouterConfigParser::new(&yaml);
let address = router_config.address()?;
let address = address
.map(RouterAddress::from)
.unwrap_or(self.state.router_address);
let health_check_enabled = router_config.health_check_enabled();
let health_check_endpoint = router_config.health_check_endpoint()?;
let health_check_path = router_config.health_check_path();
let listen_path = router_config.listen_path();

Ok(RunRouterConfigFinal {
listen_path,
address,
health_check_enabled,
health_check_endpoint,
health_check_path,
raw_config: contents.to_string(),
})
}
Err(RoverStdError::EmptyFile { .. }) => Ok(RunRouterConfigFinal::default()),
Err(err) => Err(ReadRouterConfigError::ReadFile {
path: path.clone(),
source: Box::new(err),
}),
Some(path) => match read_file_impl.read_file(&path).await {
Ok(contents) => {
let yaml = serde_yaml::from_str(&contents).map_err(|err| {
ReadRouterConfigError::Deserialization {
path: path.clone(),
source: err,
}
})?;

let router_config = RouterConfigParser::new(&yaml);
let address = router_config.address()?;
let address = address
.map(RouterAddress::from)
.unwrap_or(self.state.router_address);
let health_check_enabled = router_config.health_check_enabled();
let health_check_endpoint = router_config.health_check_endpoint()?;
let health_check_path = router_config.health_check_path();
let listen_path = router_config.listen_path();

Ok(RunRouterConfigFinal {
listen_path,
address,
health_check_enabled,
health_check_endpoint,
health_check_path,
raw_config: contents.to_string(),
})
}
}
Err(RoverStdError::EmptyFile { .. }) => Ok(RunRouterConfigFinal::default()),
Err(RoverStdError::AdhocError { .. }) => {
errln!(
"{} does not exist, creating a router config from CLI options.",
&path
);
Ok(RunRouterConfigFinal::default())
}
Err(err) => Err(ReadRouterConfigError::ReadFile {
path: path.clone(),
source: Box::new(err),
}),
},
None => Ok(RunRouterConfigFinal::default()),
}
.map(|state| RunRouterConfig { state })
Expand Down

0 comments on commit 6b4a740

Please sign in to comment.