feat(protocol): KDL parser for ServerConfig
Adds kdl_parse module with parse_server_config() that deserialises a KDL document into ServerConfig, with full validation of name, types, durations, and restart/stop blocks. Also derives Default on RestartPolicy to satisfy clippy.
This commit is contained in:
@@ -4,7 +4,11 @@ use thiserror::Error;
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ConfigError {
|
||||
#[error("failed to read {path}: {source}")]
|
||||
Io { path: PathBuf, #[source] source: std::io::Error },
|
||||
Io {
|
||||
path: PathBuf,
|
||||
#[source]
|
||||
source: std::io::Error,
|
||||
},
|
||||
|
||||
#[error("failed to parse KDL in {path}: {message}")]
|
||||
Parse { path: PathBuf, message: String },
|
||||
@@ -13,10 +17,18 @@ pub enum ConfigError {
|
||||
MissingField { path: PathBuf, field: &'static str },
|
||||
|
||||
#[error("invalid value for `{field}` in {path}: {message}")]
|
||||
InvalidValue { path: PathBuf, field: &'static str, message: String },
|
||||
InvalidValue {
|
||||
path: PathBuf,
|
||||
field: &'static str,
|
||||
message: String,
|
||||
},
|
||||
|
||||
#[error("duplicate port {port} declared by both `{name_a}` and `{name_b}`")]
|
||||
DuplicatePort { name_a: String, name_b: String, port: u16 },
|
||||
DuplicatePort {
|
||||
name_a: String,
|
||||
name_b: String,
|
||||
port: u16,
|
||||
},
|
||||
|
||||
#[error("server name `{name}` contains invalid characters (allowed: a-z, 0-9, '-', '_')")]
|
||||
InvalidName { name: String },
|
||||
@@ -33,5 +45,7 @@ pub enum RpcErrorCode {
|
||||
}
|
||||
|
||||
impl RpcErrorCode {
|
||||
pub fn as_i32(self) -> i32 { self as i32 }
|
||||
pub fn as_i32(self) -> i32 {
|
||||
self as i32
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user