Add config-parsing-time check for argument count range
This commit is contained in:
parent
46261bdfa0
commit
83a2ba0f8a
1 changed files with 15 additions and 1 deletions
|
@ -2,7 +2,7 @@ use crate::BunBunError;
|
||||||
use dirs::{config_dir, home_dir};
|
use dirs::{config_dir, home_dir};
|
||||||
use log::{debug, info, trace};
|
use log::{debug, info, trace};
|
||||||
use serde::{
|
use serde::{
|
||||||
de::{self, Deserializer, MapAccess, Visitor},
|
de::{self, Deserializer, MapAccess, Unexpected, Visitor},
|
||||||
Deserialize, Serialize,
|
Deserialize, Serialize,
|
||||||
};
|
};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -138,6 +138,20 @@ impl<'de> Deserialize<'de> for Route {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let (Some(min_args), Some(max_args)) = (min_args, max_args) {
|
||||||
|
if min_args > max_args {
|
||||||
|
{
|
||||||
|
return Err(de::Error::invalid_value(
|
||||||
|
Unexpected::Other(&format!(
|
||||||
|
"argument count range {} to {}",
|
||||||
|
min_args, max_args
|
||||||
|
)),
|
||||||
|
&"a valid argument count range",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let path = path.ok_or_else(|| de::Error::missing_field("path"))?;
|
let path = path.ok_or_else(|| de::Error::missing_field("path"))?;
|
||||||
Ok(Route {
|
Ok(Route {
|
||||||
route_type: get_route_type(&path),
|
route_type: get_route_type(&path),
|
||||||
|
|
Loading…
Reference in a new issue