1use rmcp::ErrorData;
2use thiserror::Error;
3
4pub type Result<T> = std::result::Result<T, LiteCodeError>;
5
6#[derive(Debug, Error)]
7pub enum LiteCodeError {
8 #[error("{0}")]
9 InvalidInput(String),
10 #[error("{0}")]
11 Internal(String),
12 #[error(transparent)]
13 Io(#[from] std::io::Error),
14}
15
16impl LiteCodeError {
17 pub fn invalid_input(message: impl Into<String>) -> Self {
18 Self::InvalidInput(message.into())
19 }
20
21 pub fn internal(message: impl Into<String>) -> Self {
22 Self::Internal(message.into())
23 }
24}
25
26impl From<LiteCodeError> for ErrorData {
27 fn from(value: LiteCodeError) -> Self {
28 match value {
29 LiteCodeError::InvalidInput(message) => ErrorData::invalid_params(message, None),
30 LiteCodeError::Internal(message) => ErrorData::internal_error(message, None),
31 LiteCodeError::Io(error) => ErrorData::internal_error(error.to_string(), None),
32 }
33 }
34}
35
36impl From<rmcp::service::ServerInitializeError> for LiteCodeError {
37 fn from(value: rmcp::service::ServerInitializeError) -> Self {
38 Self::internal(value.to_string())
39 }
40}
41
42impl From<tokio::task::JoinError> for LiteCodeError {
43 fn from(value: tokio::task::JoinError) -> Self {
44 Self::internal(value.to_string())
45 }
46}