Skip to content

Commit

Permalink
use thiserror to impl SerializationError
Browse files Browse the repository at this point in the history
Signed-off-by: Teo Koon Peng <[email protected]>
  • Loading branch information
koonpeng committed Jan 3, 2025
1 parent a74223c commit 35a1bb7
Showing 1 changed file with 5 additions and 26 deletions.
31 changes: 5 additions & 26 deletions src/diagram/serialization.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,18 @@
use std::{any::TypeId, error::Error, fmt::Display};
use std::any::TypeId;

use schemars::{gen::SchemaGenerator, schema::Schema, JsonSchema};
use serde::{de::DeserializeOwned, Serialize};
use tracing::debug;

use super::NodeRegistry;

#[derive(Debug)]
#[derive(thiserror::Error, Debug)]
pub enum SerializationError {
#[error("not supported")]
NotSupported,
JsonError(serde_json::Error),
}

impl Display for SerializationError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::NotSupported => f.write_str("not supported"),
Self::JsonError(err) => err.fmt(f),
}
}
}

impl Error for SerializationError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::NotSupported => None,
Self::JsonError(err) => Some(err),
}
}
}

impl From<serde_json::Error> for SerializationError {
fn from(value: serde_json::Error) -> Self {
Self::JsonError(value)
}
#[error(transparent)]
JsonError(#[from] serde_json::Error),
}

pub trait DynType {
Expand Down

0 comments on commit 35a1bb7

Please sign in to comment.