use crate::validation::ConstraintViolation;
use formualizer_common::ExcelError;
use formualizer_workbook::error::IoError;
use sheetport_spec::{ManifestIssue, ValidationError};
use thiserror::Error;
#[derive(Debug, Error)]
pub enum SheetPortError {
#[error("manifest validation failed")]
InvalidManifest { issues: Vec<ManifestIssue> },
#[error("unsupported selector for port `{port}`: {reason}")]
UnsupportedSelector { port: String, reason: String },
#[error("invalid reference `{reference}` in port `{port}`: {details}")]
InvalidReference {
port: String,
reference: String,
details: String,
},
#[error("sheet `{sheet}` referenced by port `{port}` was not found in the workbook")]
MissingSheet { port: String, sheet: String },
#[error("invariant violation for port `{port}`: {message}")]
InvariantViolation { port: String, message: String },
#[error("value did not satisfy manifest constraints")]
ConstraintViolation {
violations: Vec<ConstraintViolation>,
},
#[error("engine error: {source}")]
Engine {
#[from]
source: ExcelError,
},
#[error("workbook error: {source}")]
Workbook {
#[from]
source: IoError,
},
}
impl From<ValidationError> for SheetPortError {
fn from(err: ValidationError) -> Self {
SheetPortError::InvalidManifest {
issues: err.issues().to_vec(),
}
}
}