1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use std::fmt;
/// Errors from workbook value-type constructors and from
/// [`Workbook::from_json`](crate::Workbook::from_json) /
/// [`Workbook::to_json`](crate::Workbook::to_json).
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum WorkbookError {
/// A formula-less cell whose value is `empty` is invalid: it would be
/// byte-distinguishable from the absent cell it denotes, breaking
/// canonical uniqueness (schema spec §4). Clear a cell by removing its
/// entry from the sheet's cell map instead.
EmptyLiteral,
/// A document-level rule was violated while parsing or serializing — a
/// rule serde cannot express (schema spec §1, §2, §3, §5, §7, §8) or a
/// resource-limit breach (scope ADR Decision 5). Carries a human-readable
/// description of the first violation found.
Validation(String),
/// A sheet-management operation
/// ([`add_sheet`](crate::Workbook::add_sheet),
/// [`insert_sheet`](crate::Workbook::insert_sheet),
/// [`rename_sheet`](crate::Workbook::rename_sheet),
/// [`move_sheet`](crate::Workbook::move_sheet)) violated an invariant —
/// a duplicate sheet name under simple case folding (schema spec §2), a
/// name that is empty or exceeds the length limit (schema spec §3), the
/// per-workbook sheet cap (scope ADR Decision 5), an out-of-range tab
/// position, or an unknown sheet name. Carries a human-readable
/// description.
SheetManagement(String),
/// A workbook-level mutation
/// ([`set`](crate::Workbook::set), [`define_name`](crate::Workbook::define_name),
/// [`redefine_name`](crate::Workbook::redefine_name)) violated an invariant —
/// an empty-literal write (use clear), an unknown sheet, a syntactically
/// invalid formula for the locked engine, an invalid or non-canonical
/// named-range name/`ref`, a `ref` to a missing sheet (schema spec §7), a
/// duplicate name under simple case folding, or a per-mutation resource cap
/// (cells / text / array / formula / named-range count, scope ADR
/// Decision 5). Carries a human-readable description.
Mutation(String),
}
impl fmt::Display for WorkbookError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
WorkbookError::EmptyLiteral => write!(
f,
"a literal cell cannot hold an empty value; \
clear a cell by removing its entry instead"
),
WorkbookError::Validation(msg) => write!(f, "{msg}"),
WorkbookError::SheetManagement(msg) => write!(f, "{msg}"),
WorkbookError::Mutation(msg) => write!(f, "{msg}"),
}
}
}
impl std::error::Error for WorkbookError {}