1use tor_rpcbase::RpcError;
4
5#[derive(Clone, Debug, thiserror::Error, serde::Serialize)]
11pub enum RequestParseError {
12 #[error("Request did not have any `id` field.")]
14 IdMissing,
15
16 #[error("Request's `id` field was not an integer or a string.")]
18 IdType,
19
20 #[error("Request did not have any `obj` field.")]
22 ObjMissing,
23
24 #[error("Request's `obj` field was not a string.")]
26 ObjType,
27
28 #[error("Request had no `method` field.")]
30 MethodMissing,
31
32 #[error("Request's `method` field was not a string.")]
34 MethodType,
35
36 #[error("Request's `meta` field was not valid.")]
40 MetaType,
41
42 #[error("Request's `method` field was unrecognized")]
44 NoSuchMethod,
45
46 #[error("Parameter types incorrect for specified method")]
48 ParamType,
49
50 #[error("Request's `params` field was missing.")]
52 MissingParams,
53}
54
55impl From<RequestParseError> for RpcError {
56 fn from(err: RequestParseError) -> Self {
57 use RequestParseError as E;
58 use tor_rpcbase::RpcErrorKind as EK;
59 let kind = match err {
60 E::IdMissing
61 | E::IdType
62 | E::ObjMissing
63 | E::ObjType
64 | E::MethodMissing
65 | E::MethodType
66 | E::MetaType
67 | E::MissingParams => EK::InvalidRequest,
68 E::NoSuchMethod => EK::NoSuchMethod,
69 E::ParamType => EK::InvalidMethodParameters,
70 };
71 RpcError::new(err.to_string(), kind)
72 }
73}