@@ -4,6 +4,7 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr};
4
4
use buildstructor:: buildstructor;
5
5
use camino:: Utf8PathBuf ;
6
6
use http:: Uri ;
7
+ use rover_std:: errln;
7
8
use rover_std:: { Fs , RoverStdError } ;
8
9
use thiserror:: Error ;
9
10
@@ -130,44 +131,47 @@ impl RunRouterConfig<RunRouterConfigReadConfig> {
130
131
path : Option < & Utf8PathBuf > ,
131
132
) -> Result < RunRouterConfig < RunRouterConfigFinal > , ReadRouterConfigError > {
132
133
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
+ } )
169
161
}
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
+ } ,
171
175
None => Ok ( RunRouterConfigFinal :: default ( ) ) ,
172
176
}
173
177
. map ( |state| RunRouterConfig { state } )
0 commit comments