refactor(miette): reuse `DiagnosticError` in `protocol.rs`

This commit is contained in:
Brooks J Rady 2025-04-26 16:43:50 +01:00
parent 6d521a512a
commit 53c8330f21
1 changed files with 2 additions and 13 deletions

View File

@ -12,7 +12,7 @@ use std::{
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::MietteError; use crate::{DiagnosticError, MietteError};
/// Adds rich metadata to your Error that can be used by /// Adds rich metadata to your Error that can be used by
/// [`Report`](crate::Report) to print really nice and human-friendly error /// [`Report`](crate::Report) to print really nice and human-friendly error
@ -174,18 +174,7 @@ impl From<String> for Box<dyn Diagnostic + Send + Sync> {
impl From<Box<dyn std::error::Error + Send + Sync>> for Box<dyn Diagnostic + Send + Sync> { impl From<Box<dyn std::error::Error + Send + Sync>> for Box<dyn Diagnostic + Send + Sync> {
fn from(s: Box<dyn std::error::Error + Send + Sync>) -> Self { fn from(s: Box<dyn std::error::Error + Send + Sync>) -> Self {
#[derive(thiserror::Error)] Box::new(DiagnosticError(s))
#[error(transparent)]
struct BoxedDiagnostic(Box<dyn std::error::Error + Send + Sync>);
impl fmt::Debug for BoxedDiagnostic {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.0, f)
}
}
impl Diagnostic for BoxedDiagnostic {}
Box::new(BoxedDiagnostic(s))
} }
} }