trustfall_core/interpreter/
error.rs1use serde::{Deserialize, Serialize};
2
3use crate::{ir::FieldValue, util::DisplayVec};
4
5#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, thiserror::Error)]
6pub enum QueryArgumentsError {
7 #[error("One or more arguments required by this query were not provided: {0:?}")]
8 MissingArguments(Vec<String>),
9
10 #[error("One or more of the provided arguments are not used in this query: {0:?}")]
11 UnusedArguments(Vec<String>),
12
13 #[error(
14 "The query requires argument \"{0}\" to have type {1}, but the provided value cannot be \
15 converted to that type: {2:?}"
16 )]
17 ArgumentTypeError(String, String, FieldValue),
18
19 #[error("Multiple argument errors: {0}")]
20 MultipleErrors(DisplayVec<QueryArgumentsError>),
21}
22
23impl From<Vec<QueryArgumentsError>> for QueryArgumentsError {
24 fn from(v: Vec<QueryArgumentsError>) -> Self {
25 assert!(!v.is_empty());
26 if v.len() == 1 {
27 v.into_iter().next().unwrap()
28 } else {
29 Self::MultipleErrors(DisplayVec(v))
30 }
31 }
32}