Files
xy/crates/xy-protocol/src/error.rs
T
logaritmisk 7e59d7d050 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.
2026-05-25 11:29:05 +02:00

52 lines
1.2 KiB
Rust

use std::path::PathBuf;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum ConfigError {
#[error("failed to read {path}: {source}")]
Io {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("failed to parse KDL in {path}: {message}")]
Parse { path: PathBuf, message: String },
#[error("missing required field `{field}` in {path}")]
MissingField { path: PathBuf, field: &'static str },
#[error("invalid value for `{field}` in {path}: {message}")]
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,
},
#[error("server name `{name}` contains invalid characters (allowed: a-z, 0-9, '-', '_')")]
InvalidName { name: String },
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RpcErrorCode {
ServerNotFound = -32001,
PortConflict = -32002,
ConfigInvalid = -32003,
AlreadyRunning = -32004,
NotRunning = -32005,
SpawnFailed = -32006,
}
impl RpcErrorCode {
pub fn as_i32(self) -> i32 {
self as i32
}
}