use concinnity_cook::compile::program::{CompileFailure, ProgramError};
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) enum ReloadFailure {
Compile(CompileFailure),
Rejected(String),
Unstarted(String),
}
impl ReloadFailure {
pub(crate) fn first_error_at(&self) -> Option<String> {
let Self::Compile(failed) = self else {
return None;
};
let error = failed.errors().next()?;
let file = std::path::Path::new(&error.path)
.file_name()
.and_then(|f| f.to_str())
.unwrap_or(&error.path);
Some(format!("{file}:{}", error.line))
}
}
impl From<ProgramError> for ReloadFailure {
fn from(e: ProgramError) -> Self {
match e {
ProgramError::Compile(failed) => Self::Compile(failed),
other => Self::Unstarted(other.to_string()),
}
}
}
impl fmt::Display for ReloadFailure {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Compile(failed) => failed.fmt(f),
Self::Rejected(e) => write!(f, "pipeline rebuild rejected: {e}"),
Self::Unstarted(e) => f.write_str(e),
}
}
}