Return an error instead of panicking when too many statements (#372)

* Return an error instead of panicking when too many statements

* Improve clarity of variable names and error message
This commit is contained in:
Rob Knight 2025-07-30 20:21:39 +01:00 committed by GitHub
parent ae39ff307d
commit bde35369d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 9 deletions

View file

@ -35,6 +35,10 @@ pub enum InnerError {
PodlangParse(String),
#[error("POD Request validation error: {0}")]
PodRequestValidation(String),
#[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}")]
TooManyStatements(usize, usize),
// Other
#[error("{0}")]
Custom(String),
@ -104,4 +108,10 @@ impl Error {
pub(crate) fn pod_request_validation(e: String) -> Self {
new!(PodRequestValidation(e))
}
pub(crate) fn too_many_public_statements(found: usize, max: usize) -> Self {
new!(TooManyPublicStatements(found, max))
}
pub(crate) fn too_many_statements(found: usize, max: usize) -> Self {
new!(TooManyStatements(found, max))
}
}