swarm repositories / source
aboutsummaryrefslogtreecommitdiff
path: root/crates/ra-mcp-engine/src/error.rs
diff options
context:
space:
mode:
authormain <main@swarm.moe>2026-03-19 15:49:41 -0400
committermain <main@swarm.moe>2026-03-19 15:49:41 -0400
commitfa1bd32800b65aab31ea732dd240261b4047522c (patch)
tree2fd08af6f36b8beb3c7c941990becc1a0a091d62 /crates/ra-mcp-engine/src/error.rs
downloadadequate-rust-mcp-fa1bd32800b65aab31ea732dd240261b4047522c.zip
Release adequate-rust-mcp 1.0.0v1.0.0
Diffstat (limited to 'crates/ra-mcp-engine/src/error.rs')
-rw-r--r--crates/ra-mcp-engine/src/error.rs77
1 files changed, 77 insertions, 0 deletions
diff --git a/crates/ra-mcp-engine/src/error.rs b/crates/ra-mcp-engine/src/error.rs
new file mode 100644
index 0000000..f40e1ae
--- /dev/null
+++ b/crates/ra-mcp-engine/src/error.rs
@@ -0,0 +1,77 @@
+use crate::lsp_transport::RpcErrorPayload;
+use ra_mcp_domain::{fault::Fault, types::InvariantViolation};
+use serde_json::Value;
+use thiserror::Error;
+
+/// Engine result type.
+pub type EngineResult<T> = Result<T, EngineError>;
+
+/// Structured rust-analyzer response error.
+#[derive(Debug, Clone, Error)]
+#[error("lsp response error: code={code}, message={message}")]
+pub struct LspResponseError {
+ /// LSP JSON-RPC error code.
+ pub code: i64,
+ /// LSP JSON-RPC error message.
+ pub message: String,
+ /// Optional JSON-RPC error data payload.
+ pub data: Option<Value>,
+}
+
+/// Engine failure type.
+#[derive(Debug, Error)]
+pub enum EngineError {
+ /// I/O failure while syncing source documents.
+ #[error("io error: {0}")]
+ Io(#[from] std::io::Error),
+ /// Domain invariant was violated.
+ #[error(transparent)]
+ Invariant(#[from] InvariantViolation),
+ /// Transport/process/protocol fault.
+ #[error("engine fault: {0:?}")]
+ Fault(Fault),
+ /// rust-analyzer returned a JSON-RPC error object.
+ #[error(transparent)]
+ LspResponse(#[from] LspResponseError),
+ /// Response payload could not be deserialized into expected type.
+ #[error("invalid lsp payload for method {method}: {message}")]
+ InvalidPayload {
+ /// Request method.
+ method: &'static str,
+ /// Decoder error detail.
+ message: String,
+ },
+ /// Request params could not be serialized into JSON.
+ #[error("invalid lsp request payload for method {method}: {message}")]
+ InvalidRequest {
+ /// Request method.
+ method: &'static str,
+ /// Encoder error detail.
+ message: String,
+ },
+ /// Path to URL conversion failed.
+ #[error("path cannot be represented as file URL")]
+ InvalidFileUrl,
+}
+
+impl From<Fault> for EngineError {
+ fn from(value: Fault) -> Self {
+ Self::Fault(value)
+ }
+}
+
+impl From<RpcErrorPayload> for LspResponseError {
+ fn from(value: RpcErrorPayload) -> Self {
+ Self {
+ code: value.code,
+ message: value.message,
+ data: value.data,
+ }
+ }
+}
+
+impl From<RpcErrorPayload> for EngineError {
+ fn from(value: RpcErrorPayload) -> Self {
+ Self::LspResponse(value.into())
+ }
+}