Improved error handling (part 1)

This commit is contained in:
mdecimus
2024-07-11 18:44:51 +02:00
parent ea77a98260
commit 0c2a3f09fe
179 changed files with 3409 additions and 3048 deletions

View File

@@ -32,6 +32,7 @@ pub enum ConfigWarning {
AppliedDefault { default: String },
Unread { value: String },
Build { error: String },
Parse { error: String },
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
@@ -54,7 +55,7 @@ pub struct Rate {
pub period: Duration,
}
pub type Result<T> = std::result::Result<T, String>;
pub(crate) type Result<T> = std::result::Result<T, String>;
impl Config {
pub async fn resolve_macros(&mut self, classes: &[&str]) {
@@ -206,6 +207,9 @@ impl Config {
ConfigWarning::Unread { value } => {
format!("WARNING: Unused setting {key:?} with value {value:?}")
}
ConfigWarning::Parse { error } => {
format!("WARNING: Failed to parse {key:?}: {error}")
}
ConfigWarning::Build { error } => format!("WARNING for {key:?}: {error}"),
};
if !use_stderr {

View File

@@ -294,6 +294,15 @@ impl Config {
);
}
pub fn new_parse_warning(&mut self, key: impl AsKey, details: impl Into<String>) {
self.warnings.insert(
key.as_key(),
ConfigWarning::Parse {
error: details.into(),
},
);
}
pub fn new_build_warning(&mut self, key: impl AsKey, details: impl Into<String>) {
self.warnings.insert(
key.as_key(),