graphrecords_query/error/
grouping.rs1use crate::{Diagnostic, Failure};
2use std::{
3 error::Error,
4 fmt::{self, Display, Formatter},
5};
6
7#[derive(Debug)]
8pub struct InvalidPartitionBucketArity {
9 expected: &'static str,
10 actual: usize,
11}
12
13impl InvalidPartitionBucketArity {
14 #[must_use]
15 pub const fn new(expected: &'static str, actual: usize) -> Self {
16 Self { expected, actual }
17 }
18
19 #[must_use]
20 pub const fn expected(&self) -> &'static str {
21 self.expected
22 }
23
24 #[must_use]
25 pub const fn actual(&self) -> usize {
26 self.actual
27 }
28}
29
30impl Display for InvalidPartitionBucketArity {
31 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
32 write!(
33 formatter,
34 "partition bucket requires {} element(s), but received {}",
35 self.expected, self.actual,
36 )
37 }
38}
39
40impl Error for InvalidPartitionBucketArity {}
41
42impl Diagnostic for InvalidPartitionBucketArity {
43 fn name() -> &'static str {
44 "InvalidPartitionBucketArity"
45 }
46}
47
48#[derive(Debug)]
49pub struct MissingGroupAggregate;
50
51impl Display for MissingGroupAggregate {
52 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
53 formatter.write_str("no aggregate value for the element's group")
54 }
55}
56
57impl Error for MissingGroupAggregate {}
58
59impl Diagnostic for MissingGroupAggregate {
60 fn name() -> &'static str {
61 "MissingGroupAggregate"
62 }
63
64 fn help(&self) -> Option<String> {
65 Some(
66 "ensure every group produces a value or handle the gap with `on_error(...)`"
67 .to_string(),
68 )
69 }
70}
71
72#[derive(Debug)]
73pub struct UnresolvedGroupKeyFailures {
74 failures: Vec<Failure>,
75}
76
77impl UnresolvedGroupKeyFailures {
78 #[must_use]
79 pub const fn new(failures: Vec<Failure>) -> Self {
80 Self { failures }
81 }
82
83 #[must_use]
84 pub fn failures(&self) -> &[Failure] {
85 &self.failures
86 }
87}
88
89impl Display for UnresolvedGroupKeyFailures {
90 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
91 write!(
92 formatter,
93 "{} unresolved grouping-key failure(s) cannot be represented by this exit",
94 self.failures.len(),
95 )
96 }
97}
98
99impl Error for UnresolvedGroupKeyFailures {
100 fn source(&self) -> Option<&(dyn Error + 'static)> {
101 self.failures
102 .first()
103 .map(|failure| failure as &(dyn Error + 'static))
104 }
105}
106
107impl Diagnostic for UnresolvedGroupKeyFailures {
108 fn name() -> &'static str {
109 "UnresolvedGroupKeyFailures"
110 }
111
112 fn help(&self) -> Option<String> {
113 Some("resolve retained key failures with `on_key_error(...)` before this exit".to_string())
114 }
115}
116
117#[derive(Debug)]
118pub struct UnresolvedBucketFailures {
119 failures: Vec<Failure>,
120}
121
122impl UnresolvedBucketFailures {
123 #[must_use]
124 pub const fn new(failures: Vec<Failure>) -> Self {
125 Self { failures }
126 }
127
128 #[must_use]
129 pub fn failures(&self) -> &[Failure] {
130 &self.failures
131 }
132}
133
134impl Display for UnresolvedBucketFailures {
135 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
136 write!(
137 formatter,
138 "{} unresolved bucket failure(s) cannot be represented by this exit",
139 self.failures.len(),
140 )
141 }
142}
143
144impl Error for UnresolvedBucketFailures {
145 fn source(&self) -> Option<&(dyn Error + 'static)> {
146 self.failures
147 .first()
148 .map(|failure| failure as &(dyn Error + 'static))
149 }
150}
151
152impl Diagnostic for UnresolvedBucketFailures {
153 fn name() -> &'static str {
154 "UnresolvedBucketFailures"
155 }
156
157 fn help(&self) -> Option<String> {
158 Some(
159 "resolve retained bucket failures with `on_bucket_error(...)` before this exit"
160 .to_string(),
161 )
162 }
163}