use std::fmt;
use thiserror::Error;
use super::event::Event;
pub trait EventEmitter: Send + Sync + fmt::Debug {
fn emit(&self, event: Event) -> Result<(), EmitterError>;
}
#[derive(Debug, Error)]
#[cfg_attr(feature = "diagnostics", derive(miette::Diagnostic))]
pub enum EmitterError {
#[error("event hub closed")]
#[cfg_attr(
feature = "diagnostics",
diagnostic(
code(weavegraph::emitter::emitter_fail),
help("Check event emitter configuration and downstream handler.")
)
)]
Closed,
#[error("event emission failed: {0}")]
#[cfg_attr(
feature = "diagnostics",
diagnostic(
code(weavegraph::emitter::emitter_fail),
help("Check event emitter configuration and downstream handler.")
)
)]
Other(String),
}
impl EmitterError {
pub fn other(error: impl Into<String>) -> Self {
Self::Other(error.into())
}
}