Reduce repetition of regex error type

This commit is contained in:
Oliver Hamlet
2025-03-29 10:29:24 +00:00
parent b996406e8f
commit b4f3f8e839
4 changed files with 14 additions and 11 deletions
+5 -4
View File
@@ -1,6 +1,7 @@
//! Holds all error types related to LOOT metadata.
use std::path::PathBuf;
use fancy_regex::Error as RegexImplError;
use saphyr::Marker;
use crate::metadata::MessageContent;
@@ -124,7 +125,7 @@ impl From<saphyr::ScanError> for ParseMetadataError {
pub(super) enum MetadataParsingErrorReason {
InvalidCondition(Box<(String, loot_condition_interpreter::Error)>),
MissingKey(&'static str, YamlObjectType),
InvalidRegex(Box<fancy_regex::Error>),
InvalidRegex(Box<RegexImplError>),
InvalidMultilingualMessageContents,
UnexpectedType(ExpectedType, YamlObjectType),
UnexpectedValueType(&'static str, ExpectedType, YamlObjectType),
@@ -209,7 +210,7 @@ impl std::fmt::Display for ExpectedType {
/// Represents an error encountered while parsing and compiling a regex plugin
/// name.
#[derive(Clone, Debug)]
pub struct RegexError(Box<fancy_regex::Error>);
pub struct RegexError(Box<RegexImplError>);
impl std::fmt::Display for RegexError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@@ -223,8 +224,8 @@ impl std::error::Error for RegexError {
}
}
impl From<Box<fancy_regex::Error>> for RegexError {
fn from(value: Box<fancy_regex::Error>) -> Self {
impl From<Box<RegexImplError>> for RegexError {
fn from(value: Box<RegexImplError>) -> Self {
Self(value)
}
}
+2 -2
View File
@@ -1,6 +1,6 @@
use std::sync::LazyLock;
use fancy_regex::{Captures, Regex};
use fancy_regex::{Captures, Error as RegexImplError, Regex};
use saphyr::MarkedYaml;
use crate::logging;
@@ -219,7 +219,7 @@ struct PluginName {
}
impl PluginName {
fn new(name: &str) -> Result<Self, Box<fancy_regex::Error>> {
fn new(name: &str) -> Result<Self, Box<RegexImplError>> {
let name = trim_dot_ghost(name).to_string();
if is_regex_name(&name) {
+5 -3
View File
@@ -1,5 +1,7 @@
use std::path::PathBuf;
use fancy_regex::Error as RegexImplError;
/// Represents an error that occurred while reading a parsed plugin's data.
#[derive(Debug)]
pub struct PluginDataError(esplugin::Error);
@@ -28,7 +30,7 @@ pub(crate) enum LoadPluginError {
InvalidFilename(InvalidFilenameReason),
IoError(std::io::Error),
ParsingError(esplugin::Error),
RegexError(Box<fancy_regex::Error>),
RegexError(Box<RegexImplError>),
}
impl std::fmt::Display for LoadPluginError {
@@ -65,8 +67,8 @@ impl From<esplugin::Error> for LoadPluginError {
}
}
impl From<Box<fancy_regex::Error>> for LoadPluginError {
fn from(value: Box<fancy_regex::Error>) -> Self {
impl From<Box<RegexImplError>> for LoadPluginError {
fn from(value: Box<RegexImplError>) -> Self {
LoadPluginError::RegexError(value)
}
}
+2 -2
View File
@@ -10,7 +10,7 @@ use std::{
};
use esplugin::ParseOptions;
use fancy_regex::Regex;
use fancy_regex::{Error as RegexImplError, Regex};
use crate::{
GameType,
@@ -410,7 +410,7 @@ fn extract_bash_tags(description: &str) -> Vec<String> {
Vec::new()
}
fn extract_version(description: &str) -> Result<Option<String>, Box<fancy_regex::Error>> {
fn extract_version(description: &str) -> Result<Option<String>, Box<RegexImplError>> {
static VERSION_REGEXES: LazyLock<Box<[Regex]>> = LazyLock::new(|| {
// The string below matches the range of version strings supported by
// Pseudosem v1.0.1, excluding space separators, as they make version