ifc_tabular/error.rs
1//! Refusals raised while staging tabular records.
2
3use thiserror::Error;
4
5/// Why a tabular record was refused.
6#[derive(Debug, Clone, PartialEq, Eq, Error)]
7#[non_exhaustive]
8pub enum TabularError {
9 /// A row carries a different cell count than the first row (WR1).
10 ///
11 /// Ragged tables parse and render; the damage appears only when a
12 /// reader indexes a column the short row does not have.
13 #[error("{entity}: row {row} has {found} cells, the first row has {expected}")]
14 RaggedRow {
15 /// The entity being staged.
16 entity: &'static str,
17 /// Zero-based index of the offending row.
18 row: usize,
19 /// Cells in the first row.
20 expected: usize,
21 /// Cells in this row.
22 found: usize,
23 },
24 /// More than one row is marked as a heading (WR2).
25 #[error("{entity}: {found} heading rows, at most one is allowed")]
26 TooManyHeadings {
27 /// The entity being staged.
28 entity: &'static str,
29 /// How many rows claimed to be headings.
30 found: usize,
31 },
32 /// A required list was empty.
33 ///
34 /// The schema spells these `LIST [1:?]`, so an empty list is not a
35 /// sparse record but a malformed one.
36 #[error("{entity}.{attribute} requires at least one entry")]
37 EmptyList {
38 /// The entity being staged.
39 entity: &'static str,
40 /// The attribute that came up empty.
41 attribute: &'static str,
42 },
43 /// A required label was absent or whitespace-only.
44 ///
45 /// A blank string satisfies EXISTS while naming nothing, so it is
46 /// refused rather than written.
47 #[error("{entity}.{attribute} requires a non-blank value")]
48 BlankRequired {
49 /// The entity being staged.
50 entity: &'static str,
51 /// The attribute that was blank.
52 attribute: &'static str,
53 },
54 /// A numeric attribute was not finite.
55 #[error("{entity}.{attribute} requires a finite value")]
56 NotFinite {
57 /// The entity being staged.
58 entity: &'static str,
59 /// The offending attribute.
60 attribute: &'static str,
61 },
62}
63
64/// Result alias for tabular staging.
65pub type TabularResult<T> = Result<T, TabularError>;