From ffa87b54f08c5cfa62702838640a9fb911bdae29 Mon Sep 17 00:00:00 2001 From: Nik 'Fire Eater' Krimm Date: Tue, 7 Jan 2025 15:51:05 -0600 Subject: [PATCH] =?UTF-8?q?[BGS-150]=20[messages]=20when=20router=20config?= =?UTF-8?q?=20doesn=E2=80=99t=20exist=20at=20the=20path=20provided=20in=20?= =?UTF-8?q?`--router-config`,=20stderr=20should=20receive=20message=20`{pa?= =?UTF-8?q?th}=20does=20not=20exist,=20creating=20a=20router=20config=20fr?= =?UTF-8?q?om=20CLI=20options.`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/command/dev/next/mod.rs | 6 -- src/command/dev/next/router/config/mod.rs | 78 ++++++++++++----------- 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/command/dev/next/mod.rs b/src/command/dev/next/mod.rs index 8181efcf74..9ae05b67f5 100644 --- a/src/command/dev/next/mod.rs +++ b/src/command/dev/next/mod.rs @@ -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 { diff --git a/src/command/dev/next/router/config/mod.rs b/src/command/dev/next/router/config/mod.rs index 494b438e5a..8443ef8004 100644 --- a/src/command/dev/next/router/config/mod.rs +++ b/src/command/dev/next/router/config/mod.rs @@ -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; @@ -130,44 +131,47 @@ impl RunRouterConfig { path: Option<&Utf8PathBuf>, ) -> Result, 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 })