use crate::ast;
use crate::entities::JsonDeserializationError;
use crate::parser::unescape;
use smol_str::SmolStr;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum EstToAstError {
#[error(transparent)]
JsonDeserializationError(#[from] JsonDeserializationError),
#[error("tried to convert JSON representing a template to a static policy: {0}")]
TemplateToPolicy(#[from] ast::UnexpectedSlotError),
#[error("invalid slot name, or used in wrong position")]
InvalidSlotName,
#[error("specified a slot for `action`")]
ActionSlot,
#[error("Missing operator, found empty object")]
MissingOperator,
#[error("Found multiple operators where one was expected: {ops:?}")]
MultipleOperators {
ops: Vec<SmolStr>,
},
#[error("Multiplication must be by a constant int. Neither {arg1} nor {arg2} is a constant")]
MultiplicationByNonConstant {
arg1: ast::Expr,
arg2: ast::Expr,
},
#[error("{:?}", .0.iter().map(|e| e.to_string()).collect::<Vec<String>>())]
UnescapeError(Vec<unescape::UnescapeError>),
}
#[derive(Debug, PartialEq, Error)]
pub enum InstantiationError {
#[error("failed to instantiate template: no value provided for {slot}")]
MissedSlot {
slot: ast::SlotId,
},
}