Skip to content

Commit 773effb

Browse files
committed
[BGS-150] [messages] when router config doesn’t exist at the path provided in --router-config, stderr should receive message {path} does not exist, creating a router config from CLI options.
1 parent b5fd4f7 commit 773effb

File tree

3 files changed

+42
-43
lines changed

3 files changed

+42
-43
lines changed

src/command/dev/next/mod.rs

-6
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ impl Dev {
6262

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

65-
let _config = RunRouterConfig::default()
66-
.with_address(router_address)
67-
.with_config(&read_file_impl, router_config_path.as_ref())
68-
.await
69-
.map_err(|err| RoverError::new(anyhow!("{}", err)))?;
70-
7165
let profile = &self.opts.plugin_opts.profile;
7266
let graph_ref = &self.opts.supergraph_opts.graph_ref;
7367
if let Some(graph_ref) = graph_ref {

src/command/dev/next/router/config/mod.rs

+41-37
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr};
44
use buildstructor::buildstructor;
55
use camino::Utf8PathBuf;
66
use http::Uri;
7+
use rover_std::errln;
78
use rover_std::{Fs, RoverStdError};
89
use thiserror::Error;
910

@@ -130,44 +131,47 @@ impl RunRouterConfig<RunRouterConfigReadConfig> {
130131
path: Option<&Utf8PathBuf>,
131132
) -> Result<RunRouterConfig<RunRouterConfigFinal>, ReadRouterConfigError> {
132133
match path {
133-
Some(path) => {
134-
Fs::assert_path_exists(&path).map_err(ReadRouterConfigError::Fs)?;
135-
136-
match read_file_impl.read_file(&path).await {
137-
Ok(contents) => {
138-
let yaml = serde_yaml::from_str(&contents).map_err(|err| {
139-
ReadRouterConfigError::Deserialization {
140-
path: path.clone(),
141-
source: err,
142-
}
143-
})?;
144-
145-
let router_config = RouterConfigParser::new(&yaml);
146-
let address = router_config.address()?;
147-
let address = address
148-
.map(RouterAddress::from)
149-
.unwrap_or(self.state.router_address);
150-
let health_check_enabled = router_config.health_check_enabled();
151-
let health_check_endpoint = router_config.health_check_endpoint()?;
152-
let health_check_path = router_config.health_check_path();
153-
let listen_path = router_config.listen_path();
154-
155-
Ok(RunRouterConfigFinal {
156-
listen_path,
157-
address,
158-
health_check_enabled,
159-
health_check_endpoint,
160-
health_check_path,
161-
raw_config: contents.to_string(),
162-
})
163-
}
164-
Err(RoverStdError::EmptyFile { .. }) => Ok(RunRouterConfigFinal::default()),
165-
Err(err) => Err(ReadRouterConfigError::ReadFile {
166-
path: path.clone(),
167-
source: Box::new(err),
168-
}),
134+
Some(path) => match read_file_impl.read_file(&path).await {
135+
Ok(contents) => {
136+
let yaml = serde_yaml::from_str(&contents).map_err(|err| {
137+
ReadRouterConfigError::Deserialization {
138+
path: path.clone(),
139+
source: err,
140+
}
141+
})?;
142+
143+
let router_config = RouterConfigParser::new(&yaml);
144+
let address = router_config.address()?;
145+
let address = address
146+
.map(RouterAddress::from)
147+
.unwrap_or(self.state.router_address);
148+
let health_check_enabled = router_config.health_check_enabled();
149+
let health_check_endpoint = router_config.health_check_endpoint()?;
150+
let health_check_path = router_config.health_check_path();
151+
let listen_path = router_config.listen_path();
152+
153+
Ok(RunRouterConfigFinal {
154+
listen_path,
155+
address,
156+
health_check_enabled,
157+
health_check_endpoint,
158+
health_check_path,
159+
raw_config: contents.to_string(),
160+
})
169161
}
170-
}
162+
Err(RoverStdError::EmptyFile { .. }) => Ok(RunRouterConfigFinal::default()),
163+
Err(RoverStdError::AdhocError { .. }) => {
164+
errln!(
165+
"{} does not exist, creating a router config from CLI options.",
166+
&path
167+
);
168+
Ok(RunRouterConfigFinal::default())
169+
}
170+
Err(err) => Err(ReadRouterConfigError::ReadFile {
171+
path: path.clone(),
172+
source: Box::new(err),
173+
}),
174+
},
171175
None => Ok(RunRouterConfigFinal::default()),
172176
}
173177
.map(|state| RunRouterConfig { state })

src/command/dev/next/router/run.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rover_std::Fs;
12
use std::time::Duration;
23

34
use apollo_federation_types::config::RouterVersion;

0 commit comments

Comments
 (0)