mant_query/selectors/
error.rs1use std::{error::Error, fmt};
3
4#[derive(Debug, Clone, PartialEq, Eq)]
6pub enum ProjectionError {
7 MissingContent {
9 document: String,
11 },
12 EmptySelection,
14 EmptySelector,
16 InvalidSelector,
18 InvalidReferenceProjection(&'static str),
20 TooManySelections {
22 maximum: usize,
24 },
25 UnknownSelector {
27 document: String,
29 selector: String,
31 },
32 AmbiguousSelector {
34 document: String,
36 selector: String,
38 candidates: Vec<SelectorCandidate>,
40 },
41}
42
43#[derive(Debug, Clone, PartialEq, Eq)]
45pub struct SelectorCandidate {
46 pub path: String,
48 pub id: String,
50}
51
52impl fmt::Display for ProjectionError {
53 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
54 match self {
55 Self::MissingContent { document } => {
56 write!(formatter, "document '{document}' has no available content")
57 }
58 Self::EmptySelection => formatter.write_str("at least one outline node is required"),
59 Self::EmptySelector => formatter.write_str("outline node must not be empty"),
60 Self::InvalidSelector => mant_protocol::InvalidContentSelector.fmt(formatter),
61 Self::InvalidReferenceProjection(reason) => formatter.write_str(reason),
62 Self::TooManySelections { maximum } => {
63 write!(formatter, "at most {maximum} outline nodes may be selected")
64 }
65 Self::UnknownSelector { document, selector } => write!(
66 formatter,
67 "document '{document}' has no outline node '{selector}'; inspect its entries outline for available selectors and diagnostics"
68 ),
69 Self::AmbiguousSelector {
70 document,
71 selector,
72 candidates,
73 } => {
74 write!(
75 formatter,
76 "document '{document}' has multiple content owners for '{selector}': "
77 )?;
78 for (index, candidate) in candidates.iter().enumerate() {
79 if index > 0 {
80 formatter.write_str(", ")?;
81 }
82 write!(formatter, "{} ({})", candidate.path, candidate.id)?;
83 }
84 formatter.write_str("; select one by path or ID")
85 }
86 }
87 }
88}
89
90impl Error for ProjectionError {}