diff options
author | Ken Matsui <26405363+ken-matsui@users.noreply.github.com> | 2021-11-06 04:45:57 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-05 20:45:57 +0100 |
commit | f9cb23af654659638d9d6e57cea0a3f49c913779 (patch) | |
tree | 68e852178d5c851d1803d4b4ee4b77aa630e2947 /zellij-utils/src/input/plugins.rs | |
parent | c1cf7287abbe564230a07fafa75cb68acd73a1db (diff) |
fix(errors): Introduce thiserror to make error types simpler (#836)
Diffstat (limited to 'zellij-utils/src/input/plugins.rs')
-rw-r--r-- | zellij-utils/src/input/plugins.rs | 29 |
1 files changed, 5 insertions, 24 deletions
diff --git a/zellij-utils/src/input/plugins.rs b/zellij-utils/src/input/plugins.rs index 931d9f780..e97a8ad03 100644 --- a/zellij-utils/src/input/plugins.rs +++ b/zellij-utils/src/input/plugins.rs @@ -2,9 +2,9 @@ use std::borrow::Borrow; use std::collections::HashMap; use std::convert::TryFrom; -use std::fmt::{self, Display}; use std::fs; use std::path::{Path, PathBuf}; +use thiserror::Error; use lazy_static::lazy_static; use serde::{Deserialize, Serialize}; @@ -189,35 +189,16 @@ impl Default for PluginTypeFromYaml { } } -#[derive(Debug, PartialEq)] +#[derive(Error, Debug, PartialEq)] pub enum PluginsConfigError { + #[error("Duplication in plugin tag names is not allowed: '{}'", String::from(.0.clone()))] DuplicatePlugins(PluginTag), + #[error("Only 'file:' and 'zellij:' url schemes are supported for plugin lookup. '{0}' does not match either.")] InvalidUrl(Url), + #[error("Could not find plugin at the path: '{0:?}'")] InvalidPluginLocation(PathBuf), } -impl std::error::Error for PluginsConfigError {} -impl Display for PluginsConfigError { - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - match self { - PluginsConfigError::DuplicatePlugins(tag) => write!( - formatter, - "Duplication in plugin tag names is not allowed: '{}'", - String::from(tag.clone()) - ), - PluginsConfigError::InvalidUrl(url) => write!( - formatter, - "Only 'file:' and 'zellij:' url schemes are supported for plugin lookup. '{}' does not match either.", - url - ), - PluginsConfigError::InvalidPluginLocation(path) => write!( - formatter, - "Could not find plugin at the path: '{:?}'", path - ), - } - } -} - #[cfg(test)] mod tests { use super::*; |