diff --git a/cargo-shuttle/src/config.rs b/cargo-shuttle/src/config.rs index a6bc12104..a364455b3 100644 --- a/cargo-shuttle/src/config.rs +++ b/cargo-shuttle/src/config.rs @@ -41,11 +41,13 @@ pub trait ConfigManager: Sized { C: for<'de> Deserialize<'de>, { let path = self.path(); - let config_bytes = File::open(&path).and_then(|mut f| { - let mut buf = Vec::new(); - f.read_to_end(&mut buf)?; - Ok(buf) - })?; + let config_bytes = File::open(&path) + .and_then(|mut f| { + let mut buf = Vec::new(); + f.read_to_end(&mut buf)?; + Ok(buf) + }) + .with_context(|| anyhow!("Unable to read configuration file: {}", path.display()))?; toml::from_slice(config_bytes.as_slice()) .with_context(|| anyhow!("Invalid global configuration file: {}", path.display())) } @@ -256,7 +258,9 @@ impl RequestContext { if !global.exists() { global.create()?; } - global.open()?; + global + .open() + .context("Unable to load global configuration")?; Ok(Self { global, project: None, diff --git a/cargo-shuttle/src/lib.rs b/cargo-shuttle/src/lib.rs index 102b2c3de..a68760084 100644 --- a/cargo-shuttle/src/lib.rs +++ b/cargo-shuttle/src/lib.rs @@ -37,16 +37,10 @@ pub struct Shuttle { ctx: RequestContext, } -impl Default for Shuttle { - fn default() -> Self { - Self::new() - } -} - impl Shuttle { - pub fn new() -> Self { - let ctx = RequestContext::load_global().unwrap(); - Self { ctx } + pub fn new() -> Result { + let ctx = RequestContext::load_global()?; + Ok(Self { ctx }) } pub async fn run(mut self, mut args: Args) -> Result { @@ -479,7 +473,7 @@ mod tests { name: None, }; - let mut shuttle = Shuttle::new(); + let mut shuttle = Shuttle::new().unwrap(); Shuttle::load_project(&mut shuttle, &mut project_args).unwrap(); assert_eq!( diff --git a/cargo-shuttle/src/main.rs b/cargo-shuttle/src/main.rs index fc4f83b5c..a80e1ca15 100644 --- a/cargo-shuttle/src/main.rs +++ b/cargo-shuttle/src/main.rs @@ -6,7 +6,7 @@ use clap::Parser; async fn main() -> Result<()> { tracing_subscriber::fmt::init(); - let result = Shuttle::new().run(Args::parse()).await; + let result = Shuttle::new()?.run(Args::parse()).await; if matches!(result, Ok(CommandOutcome::DeploymentFailure)) { // Deployment failure results in a shell error exit code being returned (this allows diff --git a/cargo-shuttle/tests/integration/init.rs b/cargo-shuttle/tests/integration/init.rs index 370001605..25de27008 100644 --- a/cargo-shuttle/tests/integration/init.rs +++ b/cargo-shuttle/tests/integration/init.rs @@ -12,6 +12,7 @@ async fn cargo_shuttle_init(path: PathBuf) -> anyhow::Result { let working_directory = Path::new(".").to_path_buf(); Shuttle::new() + .unwrap() .run(Args { api_url: Some("http://shuttle.invalid:80".to_string()), project_args: ProjectArgs { @@ -39,6 +40,7 @@ async fn cargo_shuttle_init_framework(path: PathBuf) -> anyhow::Result u16 { let port = pick_unused_port().unwrap(); let run_args = RunArgs { port }; - let runner = Shuttle::new().run(Args { + let runner = Shuttle::new().unwrap().run(Args { api_url: Some("http://shuttle.invalid:80".to_string()), project_args: ProjectArgs { working_directory: working_directory.clone(),