feat(protocol): ServerConfig + ConfigError + RpcErrorCode
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
Reference in New Issue
Block a user