Validate config on load; document the SDK's core traits
Some checks failed
CI / check (push) Failing after 53s

Config::load now checks the SID is 3 alphanumeric chars and that
server.name and uplink.host are set, failing with a clear message
instead of a cryptic link-time error. Give the Service and Protocol
traits and ServiceCtx proper rustdoc so cargo doc is useful to module
authors.
This commit is contained in:
Jean Chevronnet 2026-07-14 23:31:44 +00:00
parent 955e55d47f
commit 0ed6684522
No known key found for this signature in database
2 changed files with 29 additions and 6 deletions

View file

@ -278,6 +278,24 @@ fn default_scram_iterations() -> u32 {
impl Config {
pub fn load(path: &str) -> anyhow::Result<Self> {
let raw = std::fs::read_to_string(path)?;
Ok(toml::from_str(&raw)?)
let cfg: Config = toml::from_str(&raw)?;
cfg.validate()?;
Ok(cfg)
}
// Catch the common misconfigurations up front with a clear message, rather
// than failing cryptically at link time.
fn validate(&self) -> anyhow::Result<()> {
let sid = &self.server.sid;
if sid.len() != 3 || !sid.chars().all(|c| c.is_ascii_alphanumeric()) {
anyhow::bail!("server.sid must be exactly 3 alphanumeric characters (got {sid:?})");
}
if self.server.name.trim().is_empty() {
anyhow::bail!("server.name must not be empty");
}
if self.uplink.host.trim().is_empty() {
anyhow::bail!("uplink.host must not be empty");
}
Ok(())
}
}