feat(protocol): ServerConfig + ConfigError + RpcErrorCode

This commit is contained in:
2026-05-25 11:23:57 +02:00
parent 5a0963665d
commit 355d0debda
3 changed files with 60 additions and 1 deletions
+20
View File
@@ -68,6 +68,26 @@ impl Default for StopConfig {
}
}
use std::collections::BTreeMap;
use std::path::PathBuf;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ServerConfig {
pub name: String,
pub command: PathBuf,
#[serde(default)]
pub args: Vec<String>,
pub port: u16,
#[serde(default)]
pub env: BTreeMap<String, String>,
#[serde(default)]
pub working_dir: Option<PathBuf>,
#[serde(default)]
pub restart: RestartConfig,
#[serde(default)]
pub stop: StopConfig,
}
#[cfg(test)]
mod tests {
use super::*;
+37
View File
@@ -0,0 +1,37 @@
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 }
}
+3 -1
View File
@@ -1,7 +1,9 @@
//! Wire types and config schema shared between the xy daemon and CLI.
pub mod config;
pub mod error;
pub mod state;
pub use config::{RestartConfig, RestartPolicy, StopConfig};
pub use config::{RestartConfig, RestartPolicy, ServerConfig, StopConfig};
pub use error::{ConfigError, RpcErrorCode};
pub use state::ServerState;