Add max input POD check to MainPodBuilder (#440)
This commit is contained in:
parent
42f979c408
commit
32dc85471d
4 changed files with 16 additions and 4 deletions
|
|
@ -35,6 +35,8 @@ pub enum InnerError {
|
|||
PodlangParse(String),
|
||||
#[error("POD Request validation error: {0}")]
|
||||
PodRequestValidation(String),
|
||||
#[error("Too many input PODs provided: {0} were provided, but the maximum is {1}")]
|
||||
TooManyInputPods(usize, usize),
|
||||
#[error("Too many public statements provided: {0} were provided, but the maximum is {1}")]
|
||||
TooManyPublicStatements(usize, usize),
|
||||
#[error("Too many statements provided: {0} were provided, but the maximum is {1}")]
|
||||
|
|
@ -108,6 +110,9 @@ impl Error {
|
|||
pub(crate) fn pod_request_validation(e: String) -> Self {
|
||||
new!(PodRequestValidation(e))
|
||||
}
|
||||
pub(crate) fn too_many_input_pods(found: usize, max: usize) -> Self {
|
||||
new!(TooManyInputPods(found, max))
|
||||
}
|
||||
pub(crate) fn too_many_public_statements(found: usize, max: usize) -> Self {
|
||||
new!(TooManyPublicStatements(found, max))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -164,8 +164,15 @@ impl MainPodBuilder {
|
|||
dict_contains: Vec::new(),
|
||||
}
|
||||
}
|
||||
pub fn add_pod(&mut self, pod: MainPod) {
|
||||
pub fn add_pod(&mut self, pod: MainPod) -> Result<()> {
|
||||
self.input_pods.push(pod);
|
||||
match self.input_pods.len() > self.params.max_input_pods {
|
||||
true => Err(Error::too_many_input_pods(
|
||||
self.input_pods.len(),
|
||||
self.params.max_input_pods,
|
||||
)),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
pub fn insert(&mut self, public: bool, st_op: (Statement, Operation)) -> Result<()> {
|
||||
// TODO: Do error handling instead of panic
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue