From e807488471746a8b1b0fe8ba6cb561746801d18a Mon Sep 17 00:00:00 2001 From: naskya Date: Fri, 21 Jun 2024 09:10:28 +0900 Subject: [PATCH] update error enum names --- src/command/config.rs | 5 +++-- src/command/config/update.rs | 1 + src/command/config/update/v1.rs | 3 +++ src/command/config/validate.rs | 1 + src/command/mod.rs | 3 ++- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/command/config.rs b/src/command/config.rs index 76d60ee..0c9974a 100644 --- a/src/command/config.rs +++ b/src/command/config.rs @@ -16,8 +16,9 @@ pub(crate) enum Commands { Validate, } +/// Errors that can happen in `config` subcommand #[derive(thiserror::Error, Debug)] -pub(crate) enum Error { +pub(crate) enum ConfigError { #[error(transparent)] Update(#[from] update::UpdateError), #[error(transparent)] @@ -89,7 +90,7 @@ fn next_revision() -> Result, RevisionCheckError> { Ok(next_revision) } -pub(crate) async fn run(command: Commands) -> Result<(), Error> { +pub(crate) async fn run(command: Commands) -> Result<(), ConfigError> { match command { Commands::Update { revision } => update::run(revision).await?, Commands::Validate => validate::run()?, diff --git a/src/command/config/update.rs b/src/command/config/update.rs index 2fcec09..802d65e 100644 --- a/src/command/config/update.rs +++ b/src/command/config/update.rs @@ -10,6 +10,7 @@ use chrono::Local; use color_print::cprintln; use std::{fs, io}; +/// Errors that happen in `config update` subcommand #[derive(thiserror::Error, Debug)] pub(crate) enum UpdateError { #[error(transparent)] diff --git a/src/command/config/update/v1.rs b/src/command/config/update/v1.rs index d208184..fbe5eb2 100644 --- a/src/command/config/update/v1.rs +++ b/src/command/config/update/v1.rs @@ -15,6 +15,7 @@ use std::{ use url::Url; use yaml_rust::{Yaml, YamlLoader}; +/// Errors that can happen in `config update v1` subcommand #[derive(thiserror::Error, Debug)] pub(crate) enum Error { #[error("failed to parse the old config file ({})", OLD_CONFIG_PATH)] @@ -29,6 +30,7 @@ pub(crate) enum Error { InvalidUrl(#[from] url::ParseError), } +/// Errors that can happen while reading `.config/default.yml` #[derive(thiserror::Error, Debug)] pub(crate) enum ReadYamlConfigError { #[error(transparent)] @@ -39,6 +41,7 @@ pub(crate) enum ReadYamlConfigError { InvalidConfig(String), } +/// Errors that can happen while writing `config/{server,client}.toml` #[derive(thiserror::Error, Debug)] pub(crate) enum WriteTomlConfigError { #[error("failed to serialize the new server config into TOML format")] diff --git a/src/command/config/validate.rs b/src/command/config/validate.rs index 0db2da5..5336bec 100644 --- a/src/command/config/validate.rs +++ b/src/command/config/validate.rs @@ -8,6 +8,7 @@ use color_print::cprintln; use std::{fs, io::Read}; use validator::Validate; +/// Errors that can happen in `config validate` subcommand #[derive(thiserror::Error, Debug)] pub(crate) enum ValidationError { #[error(transparent)] diff --git a/src/command/mod.rs b/src/command/mod.rs index a88ec00..65a867e 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -5,10 +5,11 @@ mod version; use clap::{Parser, Subcommand}; +/// Errors that can happen in any commands #[derive(thiserror::Error, Debug)] pub(crate) enum Error { #[error(transparent)] - Config(#[from] config::Error), + Config(#[from] config::ConfigError), } #[derive(Parser)]