Skip to main content

prosaic_core/
error.rs

1#[cfg(not(feature = "std"))]
2use alloc::string::String;
3#[cfg(not(feature = "std"))]
4use alloc::vec::Vec;
5
6use thiserror::Error;
7
8#[derive(Debug, Error, PartialEq)]
9pub enum ProsaicError {
10    #[error("missing slot `{slot}` in template `{template}`")]
11    MissingSlot { template: String, slot: String },
12
13    #[error("unknown template `{0}`")]
14    UnknownTemplate(String),
15
16    #[error("invalid pipe `{pipe}`: {reason}")]
17    InvalidPipe { pipe: String, reason: String },
18
19    #[error("grammar error: {0}")]
20    GrammarError(String),
21
22    #[error("template parse error in `{template}` at position {position}: {reason}")]
23    TemplateParseError {
24        template: String,
25        position: usize,
26        reason: String,
27    },
28
29    /// Returned when the faithfulness gate is enabled and the rendered output
30    /// fails the precision threshold or has a polarity mismatch. The session
31    /// state is rolled back as if the render had not occurred.
32    #[error("faithfulness rejected: precision {precision:.3}, polarity_match {polarity_match}")]
33    FaithfulnessRejection {
34        precision: f32,
35        polarity_match: bool,
36    },
37
38    /// Returned by `register_partial` when registering the partial would
39    /// introduce a direct or indirect `{>name}` cycle. The `cycle` field
40    /// carries the names involved in the offending chain in traversal order,
41    /// repeating the entry partial at the tail so the cycle reads
42    /// `a -> b -> a`.
43    #[error("recursive partial cycle detected: {}", cycle.join(" -> "))]
44    RecursivePartial { cycle: Vec<String> },
45}