update error enum names

This commit is contained in:
naskya 2024-06-21 09:10:28 +09:00
parent a09555b7d9
commit e807488471
Signed by: naskya
GPG key ID: 712D413B3A9FED5C
5 changed files with 10 additions and 3 deletions

View file

@ -16,8 +16,9 @@ pub(crate) enum Commands {
Validate, Validate,
} }
/// Errors that can happen in `config` subcommand
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub(crate) enum Error { pub(crate) enum ConfigError {
#[error(transparent)] #[error(transparent)]
Update(#[from] update::UpdateError), Update(#[from] update::UpdateError),
#[error(transparent)] #[error(transparent)]
@ -89,7 +90,7 @@ fn next_revision() -> Result<Option<Revision>, RevisionCheckError> {
Ok(next_revision) Ok(next_revision)
} }
pub(crate) async fn run(command: Commands) -> Result<(), Error> { pub(crate) async fn run(command: Commands) -> Result<(), ConfigError> {
match command { match command {
Commands::Update { revision } => update::run(revision).await?, Commands::Update { revision } => update::run(revision).await?,
Commands::Validate => validate::run()?, Commands::Validate => validate::run()?,

View file

@ -10,6 +10,7 @@ use chrono::Local;
use color_print::cprintln; use color_print::cprintln;
use std::{fs, io}; use std::{fs, io};
/// Errors that happen in `config update` subcommand
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub(crate) enum UpdateError { pub(crate) enum UpdateError {
#[error(transparent)] #[error(transparent)]

View file

@ -15,6 +15,7 @@ use std::{
use url::Url; use url::Url;
use yaml_rust::{Yaml, YamlLoader}; use yaml_rust::{Yaml, YamlLoader};
/// Errors that can happen in `config update v1` subcommand
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub(crate) enum Error { pub(crate) enum Error {
#[error("failed to parse the old config file ({})", OLD_CONFIG_PATH)] #[error("failed to parse the old config file ({})", OLD_CONFIG_PATH)]
@ -29,6 +30,7 @@ pub(crate) enum Error {
InvalidUrl(#[from] url::ParseError), InvalidUrl(#[from] url::ParseError),
} }
/// Errors that can happen while reading `.config/default.yml`
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub(crate) enum ReadYamlConfigError { pub(crate) enum ReadYamlConfigError {
#[error(transparent)] #[error(transparent)]
@ -39,6 +41,7 @@ pub(crate) enum ReadYamlConfigError {
InvalidConfig(String), InvalidConfig(String),
} }
/// Errors that can happen while writing `config/{server,client}.toml`
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub(crate) enum WriteTomlConfigError { pub(crate) enum WriteTomlConfigError {
#[error("failed to serialize the new server config into TOML format")] #[error("failed to serialize the new server config into TOML format")]

View file

@ -8,6 +8,7 @@ use color_print::cprintln;
use std::{fs, io::Read}; use std::{fs, io::Read};
use validator::Validate; use validator::Validate;
/// Errors that can happen in `config validate` subcommand
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub(crate) enum ValidationError { pub(crate) enum ValidationError {
#[error(transparent)] #[error(transparent)]

View file

@ -5,10 +5,11 @@ mod version;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
/// Errors that can happen in any commands
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub(crate) enum Error { pub(crate) enum Error {
#[error(transparent)] #[error(transparent)]
Config(#[from] config::Error), Config(#[from] config::ConfigError),
} }
#[derive(Parser)] #[derive(Parser)]