Skip to main content

formualizer_sheetport/
error.rs

1use crate::validation::ConstraintViolation;
2use formualizer_common::ExcelError;
3use formualizer_workbook::error::IoError;
4use sheetport_spec::{ManifestIssue, ValidationError};
5use thiserror::Error;
6
7/// Errors produced when constructing or operating a SheetPort runtime.
8#[derive(Debug, Error)]
9pub enum SheetPortError {
10    /// Manifest failed canonical validation.
11    #[error("manifest validation failed")]
12    InvalidManifest { issues: Vec<ManifestIssue> },
13    /// Selector combination is not yet supported for the given port.
14    #[error("unsupported selector for port `{port}`: {reason}")]
15    UnsupportedSelector { port: String, reason: String },
16    /// Reference string could not be parsed.
17    #[error("invalid reference `{reference}` in port `{port}`: {details}")]
18    InvalidReference {
19        port: String,
20        reference: String,
21        details: String,
22    },
23    /// Referenced sheet was not present in the workbook.
24    #[error("sheet `{sheet}` referenced by port `{port}` was not found in the workbook")]
25    MissingSheet { port: String, sheet: String },
26    /// Structural invariant could not be satisfied.
27    #[error("invariant violation for port `{port}`: {message}")]
28    InvariantViolation { port: String, message: String },
29    /// Input or resolved data violated manifest constraints.
30    #[error("value did not satisfy manifest constraints")]
31    ConstraintViolation {
32        violations: Vec<ConstraintViolation>,
33    },
34    /// Underlying engine reported an evaluation error.
35    #[error("engine error: {source}")]
36    Engine {
37        #[from]
38        source: ExcelError,
39    },
40    /// Failure when interacting with the underlying workbook backend.
41    #[error("workbook error: {source}")]
42    Workbook {
43        #[from]
44        source: IoError,
45    },
46}
47
48impl From<ValidationError> for SheetPortError {
49    fn from(err: ValidationError) -> Self {
50        SheetPortError::InvalidManifest {
51            issues: err.issues().to_vec(),
52        }
53    }
54}