From 5315bac0c5090e64e1a9b79d423f4d9236390c0d Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Fri, 20 Sep 2024 22:25:29 -0700 Subject: [PATCH] split out separate error type for serve command --- src/cli.rs | 3 ++- src/cli/serve.rs | 4 ++-- src/error.rs | 10 ++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index cb8f4154..c997ad67 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -60,7 +60,8 @@ pub(crate) struct ServeArgs { impl Args { pub(crate) async fn run(self) -> Result<(), error::Main> { match self.command { - Command::Serve(args) => serve::run(args).await, + Command::Serve(args) => serve::run(args).await?, } + Ok(()) } } diff --git a/src/cli/serve.rs b/src/cli/serve.rs index 71980e42..d8345c11 100644 --- a/src/cli/serve.rs +++ b/src/cli/serve.rs @@ -44,8 +44,8 @@ use crate::{ utils::error::{Error, Result}, }; -pub(crate) async fn run(args: ServeArgs) -> Result<(), error::Main> { - use error::Main as Error; +pub(crate) async fn run(args: ServeArgs) -> Result<(), error::ServeCommand> { + use error::ServeCommand as Error; let config = config::load(args.config.config.as_ref()).await?; diff --git a/src/error.rs b/src/error.rs index 70f0124e..d2fcae24 100644 --- a/src/error.rs +++ b/src/error.rs @@ -40,6 +40,16 @@ impl fmt::Display for DisplayWithSources<'_> { #[allow(missing_docs)] #[derive(Error, Debug)] pub(crate) enum Main { + #[error(transparent)] + ServeCommand(#[from] ServeCommand), +} + +/// Errors returned from the `serve` CLI subcommand. +// Missing docs are allowed here since that kind of information should be +// encoded in the error messages themselves anyway. +#[allow(missing_docs)] +#[derive(Error, Debug)] +pub(crate) enum ServeCommand { #[error("failed to load configuration")] Config(#[from] Config),