copperlace/render/
error.rs1use std::fmt;
2
3#[derive(Debug, PartialEq, Eq)]
5pub enum RenderError {
6 UnknownRule(String),
8 UnknownProcessor(String),
10 ProcessorError { processor: String, message: String },
12 InvalidExpression(String),
14 EmptyChoice,
16 ExhaustedUniqueChoice(String),
18 UnsupportedUniqueChoice(String),
20 InvalidWeightedChoice(String),
22 CircularRuleReference(Vec<String>),
24 UnsupportedValue(String),
26 UnsupportedIterationSource {
28 source: String,
30 value_type: String,
32 },
33 ImmutableLoopBinding(String),
35 InvalidConfigRoot,
37 UnsupportedStructuredTarget(String),
39 JsonSerialization(String),
41}
42
43impl fmt::Display for RenderError {
44 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
45 match self {
46 RenderError::UnknownRule(rule) => write!(formatter, "unknown rule: {rule}"),
47 RenderError::UnknownProcessor(processor) => {
48 write!(formatter, "unknown processor: {processor}")
49 }
50 RenderError::ProcessorError { processor, message } => {
51 write!(formatter, "processor {processor} failed: {message}")
52 }
53 RenderError::InvalidExpression(expression) => {
54 write!(formatter, "invalid template expression: {expression}")
55 }
56 RenderError::EmptyChoice => write!(formatter, "cannot render an empty choice"),
57 RenderError::ExhaustedUniqueChoice(rule) => {
58 write!(formatter, "exhausted unique choice: {rule}")
59 }
60 RenderError::UnsupportedUniqueChoice(rule) => {
61 write!(formatter, "unique choice target is not a choice: {rule}")
62 }
63 RenderError::InvalidWeightedChoice(message) => {
64 write!(formatter, "invalid weighted choice: {message}")
65 }
66 RenderError::CircularRuleReference(cycle) => {
67 write!(formatter, "circular rule reference: {}", cycle.join(" -> "))
68 }
69 RenderError::UnsupportedValue(value_type) => {
70 write!(formatter, "unsupported value type: {value_type}")
71 }
72 RenderError::UnsupportedIterationSource { source, value_type } => {
73 write!(
74 formatter,
75 "iteration source is not iterable: {source} ({value_type})"
76 )
77 }
78 RenderError::ImmutableLoopBinding(name) => {
79 write!(formatter, "cannot overwrite immutable loop binding: {name}")
80 }
81 RenderError::InvalidConfigRoot => write!(formatter, "config root must be an object"),
82 RenderError::UnsupportedStructuredTarget(rule) => {
83 write!(
84 formatter,
85 "structured render target must be an object: {rule}"
86 )
87 }
88 RenderError::JsonSerialization(message) => {
89 write!(
90 formatter,
91 "failed to serialize structured value as JSON: {message}"
92 )
93 }
94 }
95 }
96}
97
98impl std::error::Error for RenderError {}