|
10 | 10 | //! |
11 | 11 | //! See: [Error Handling](https://agentclientprotocol.com/protocol/overview#error-handling) |
12 | 12 |
|
13 | | -use std::{fmt::Display, ops::Deref as _}; |
| 13 | +use std::fmt::Display; |
14 | 14 |
|
15 | 15 | use schemars::JsonSchema; |
16 | 16 | use serde::{Deserialize, Serialize}; |
@@ -52,37 +52,44 @@ impl Error { |
52 | 52 | /// |
53 | 53 | /// This method is chainable and allows attaching context-specific information |
54 | 54 | /// to help with debugging or provide more details about the error. |
| 55 | + #[must_use] |
55 | 56 | pub fn with_data(mut self, data: impl Into<serde_json::Value>) -> Self { |
56 | 57 | self.data = Some(data.into()); |
57 | 58 | self |
58 | 59 | } |
59 | 60 |
|
60 | 61 | /// Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text. |
| 62 | + #[must_use] |
61 | 63 | pub fn parse_error() -> Self { |
62 | 64 | Error::new(ErrorCode::PARSE_ERROR) |
63 | 65 | } |
64 | 66 |
|
65 | 67 | /// The JSON sent is not a valid Request object. |
| 68 | + #[must_use] |
66 | 69 | pub fn invalid_request() -> Self { |
67 | 70 | Error::new(ErrorCode::INVALID_REQUEST) |
68 | 71 | } |
69 | 72 |
|
70 | 73 | /// The method does not exist / is not available. |
| 74 | + #[must_use] |
71 | 75 | pub fn method_not_found() -> Self { |
72 | 76 | Error::new(ErrorCode::METHOD_NOT_FOUND) |
73 | 77 | } |
74 | 78 |
|
75 | 79 | /// Invalid method parameter(s). |
| 80 | + #[must_use] |
76 | 81 | pub fn invalid_params() -> Self { |
77 | 82 | Error::new(ErrorCode::INVALID_PARAMS) |
78 | 83 | } |
79 | 84 |
|
80 | 85 | /// Internal JSON-RPC error. |
| 86 | + #[must_use] |
81 | 87 | pub fn internal_error() -> Self { |
82 | 88 | Error::new(ErrorCode::INTERNAL_ERROR) |
83 | 89 | } |
84 | 90 |
|
85 | 91 | /// Authentication required. |
| 92 | + #[must_use] |
86 | 93 | pub fn auth_required() -> Self { |
87 | 94 | Error::new(ErrorCode::AUTH_REQUIRED) |
88 | 95 | } |
@@ -181,7 +188,7 @@ impl Display for Error { |
181 | 188 |
|
182 | 189 | impl From<anyhow::Error> for Error { |
183 | 190 | fn from(error: anyhow::Error) -> Self { |
184 | | - Error::into_internal_error(error.deref()) |
| 191 | + Error::into_internal_error(&*error) |
185 | 192 | } |
186 | 193 | } |
187 | 194 |
|
|
0 commit comments