formualizer_sheetport/
error.rs1use crate::validation::ConstraintViolation;
2use formualizer_common::ExcelError;
3use formualizer_workbook::error::IoError;
4use sheetport_spec::{ManifestIssue, ValidationError};
5use thiserror::Error;
6
7#[derive(Debug, Error)]
9#[non_exhaustive]
10pub enum SheetPortError {
11 #[error("manifest validation failed")]
13 InvalidManifest { issues: Vec<ManifestIssue> },
14 #[error("unsupported selector for port `{port}`: {reason}")]
16 UnsupportedSelector { port: String, reason: String },
17 #[error("invalid reference `{reference}` in port `{port}`: {details}")]
19 InvalidReference {
20 port: String,
21 reference: String,
22 details: String,
23 },
24 #[error("sheet `{sheet}` referenced by port `{port}` was not found in the workbook")]
26 MissingSheet { port: String, sheet: String },
27 #[error("invariant violation for port `{port}`: {message}")]
29 InvariantViolation { port: String, message: String },
30 #[error(
32 "layout selector for port `{port}` on sheet `{sheet}` exhausted {limit} rows from {scan_start} using `{termination}`"
33 )]
34 LayoutExhausted {
35 port: String,
36 sheet: String,
37 termination: String,
38 scan_start: u32,
39 limit: u32,
40 observed: u32,
41 },
42 #[error("selector safety error for port `{port}`: {reason}")]
44 SelectorSafety { port: String, reason: String },
45 #[error("value did not satisfy manifest constraints")]
47 ConstraintViolation {
48 violations: Vec<ConstraintViolation>,
49 },
50 #[error("batch failed ({primary}); baseline restoration also failed ({restoration})")]
52 BatchRestoration {
53 primary: Box<SheetPortError>,
54 restoration: Box<SheetPortError>,
55 },
56 #[error("engine error: {source}")]
58 Engine {
59 #[from]
60 source: ExcelError,
61 },
62 #[error("workbook error: {source}")]
64 Workbook {
65 #[from]
66 source: IoError,
67 },
68}
69
70impl From<ValidationError> for SheetPortError {
71 fn from(err: ValidationError) -> Self {
72 SheetPortError::InvalidManifest {
73 issues: err.issues().to_vec(),
74 }
75 }
76}