#[non_exhaustive]pub struct Error {
pub code: ErrorCode,
pub message: String,
pub data: Option<Value>,
/* private fields */
}Expand description
A JSON-RPC error object, independent of the ACP protocol version.
This is the error type of every SDK callback and connection method. An error returned from a request handler is sent to the peer as an Error Response with exactly this code, message and data.
Build errors with the shared constructors below, or with a schema
version’s constructors followed by .into() when the error data differs
between versions:
| Code | Constructor |
|---|---|
-32700 | Error::parse_error |
-32600 | Error::invalid_request |
-32601 | Error::method_not_found |
-32602 | Error::invalid_params |
-32603 | Error::internal_error, Error::into_internal_error |
-32800 | Error::request_cancelled |
-32000 | Error::auth_required |
-32002 | v1::schema::Error::resource_not_found(uri), v1::schema::Error::session_not_found(id), v2::schema::Error::resource_not_found(), v2::schema::Error::session_not_found(id) |
-32022 | v2::schema::Error::unsupported_protocol_version(requested, supported) |
Convert back with v1::schema::Error::from(error) or
v2::schema::Error::from(error) to use a schema version’s view of the
error. Typed v2 error data is read with serde_json:
use agent_client_protocol::{Error, v2::schema};
let error: Error = schema::Error::session_not_found("sess_1").into();
if error.code == schema::ErrorCode::ResourceNotFound
&& let Some(data) = error.data.clone()
&& let Ok(data) = serde_json::from_value::<schema::SessionNotFoundErrorData>(data)
{
assert_eq!(data.session_id.0.as_ref(), "sess_1");
}Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.code: ErrorCodeThe JSON-RPC error code.
message: StringA short description of the error.
data: Option<Value>Optional additional information about the error.
Some(Value::Null) is sent as an explicit "data": null; None
omits the field.
Implementations§
Source§impl Error
impl Error
Sourcepub fn new(code: impl Into<ErrorCode>, message: impl Into<String>) -> Self
pub fn new(code: impl Into<ErrorCode>, message: impl Into<String>) -> Self
Creates an error with the given code and message and no data.
Sourcepub fn data(self, data: impl IntoOption<Value>) -> Self
pub fn data(self, data: impl IntoOption<Value>) -> Self
Sets the error’s data, replacing any existing data.
Sourcepub fn parse_error() -> Self
pub fn parse_error() -> Self
-32700: invalid JSON was received.
Sourcepub fn invalid_request() -> Self
pub fn invalid_request() -> Self
-32600: the JSON sent is not a valid request object.
Sourcepub fn method_not_found() -> Self
pub fn method_not_found() -> Self
-32601: the method does not exist or is not available.
Sourcepub fn invalid_params() -> Self
pub fn invalid_params() -> Self
-32602: invalid method parameters.
Sourcepub fn internal_error() -> Self
pub fn internal_error() -> Self
-32603: internal JSON-RPC error.
Sourcepub fn request_cancelled() -> Self
pub fn request_cancelled() -> Self
-32800: the request was cancelled, either by the caller or because
of resource constraints or shutdown.
Sourcepub fn auth_required() -> Self
pub fn auth_required() -> Self
-32000: authentication is required before this operation.
Sourcepub fn into_internal_error(err: impl Error) -> Self
pub fn into_internal_error(err: impl Error) -> Self
Converts any error into an internal error (-32603) whose data is the
error’s string representation.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Error
impl<'de> Deserialize<'de> for Error
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Error
Source§impl Error for Error
impl Error for Error
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<Error> for RawJsonRpcError
impl From<Error> for RawJsonRpcError
Source§impl From<UnknownToolError> for Error
Available on crate feature schemars only.
impl From<UnknownToolError> for Error
schemars only.Source§fn from(error: UnknownToolError) -> Self
fn from(error: UnknownToolError) -> Self
Source§impl JsonSchema for Error
Available on crate feature schemars only.
impl JsonSchema for Error
schemars only.Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreAuto Trait Implementations§
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
impl UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.