refactor(deps): remove `thiserror` dependency

This commit is contained in:
Brooks J Rady 2025-04-26 19:36:47 +01:00
parent 1f276bf80e
commit cca8cac29c
2 changed files with 61 additions and 9 deletions

View File

@ -22,17 +22,16 @@ members = ["tools/*"]
[dependencies]
miette.workspace = true
thiserror.workspace = true
num = "0.4.2"
winnow = { version = "=0.6.24", features = ["alloc", "unstable-recover"] }
kdlv1 = { package = "kdl", version = "4.7.0", optional = true }
[workspace.dependencies]
miette = "7.2.0"
thiserror = "1.0.40"
miette = { git = "https://github.com/TheLostLambda/miette.git" }
[dev-dependencies]
miette = { workspace = true, features = ["fancy"] }
thiserror = "2.0.12"
pretty_assertions = "1.3.0"
# The profile that 'dist' will build with

View File

@ -1,7 +1,6 @@
use std::sync::Arc;
use std::{error::Error, fmt::Display, sync::Arc};
use miette::{Diagnostic, SourceSpan};
use thiserror::Error;
#[cfg(doc)]
use {
@ -34,8 +33,7 @@ use {
/// ╰────
/// help: Floating point numbers must be base 10, and have numbers after the decimal point.
/// ```
#[derive(Debug, Diagnostic, Clone, Eq, PartialEq, Error)]
#[error("Failed to parse KDL document")]
#[derive(Debug, Diagnostic, Clone, Eq, PartialEq)]
pub struct KdlError {
/// Original input that this failure came from.
#[source_code]
@ -46,11 +44,17 @@ pub struct KdlError {
pub diagnostics: Vec<KdlDiagnostic>,
}
impl Display for KdlError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Failed to parse KDL document")
}
}
impl Error for KdlError {}
/// An individual diagnostic message for a KDL parsing issue.
///
/// While generally signifying errors, they can also be treated as warnings.
#[derive(Debug, Diagnostic, Clone, Eq, PartialEq, Error)]
#[error("{}", message.clone().unwrap_or_else(|| "Unexpected error".into()))]
#[derive(Debug, Diagnostic, Clone, Eq, PartialEq)]
pub struct KdlDiagnostic {
/// Shared source for the diagnostic.
#[source_code]
@ -75,6 +79,17 @@ pub struct KdlDiagnostic {
pub severity: miette::Severity,
}
impl Display for KdlDiagnostic {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let message = self
.message
.clone()
.unwrap_or_else(|| "Unexpected error".into());
write!(f, "{message}")
}
}
impl Error for KdlDiagnostic {}
#[cfg(feature = "v1")]
impl From<kdlv1::KdlError> for KdlError {
fn from(value: kdlv1::KdlError) -> Self {
@ -92,3 +107,41 @@ impl From<kdlv1::KdlError> for KdlError {
}
}
}
#[cfg(test)]
mod tests {
use std::error::Error;
use super::*;
#[test]
fn kdl_error() {
let kdl_error = KdlError {
input: Default::default(),
diagnostics: Default::default(),
};
assert_eq!(kdl_error.to_string(), "Failed to parse KDL document");
assert!(kdl_error.source().is_none());
}
#[test]
fn kdl_diagnostic() {
let mut kdl_diagnostic = KdlDiagnostic {
input: Default::default(),
span: SourceSpan::new(0.into(), 1),
message: Default::default(),
label: Default::default(),
help: Default::default(),
severity: Default::default(),
};
assert_eq!(kdl_diagnostic.to_string(), "Unexpected error");
assert!(kdl_diagnostic.source().is_none());
kdl_diagnostic.message = Some("mega bad news, kiddo".to_owned());
assert_eq!(kdl_diagnostic.to_string(), "mega bad news, kiddo");
assert!(kdl_diagnostic.source().is_none());
}
}