Skip to content

Commit 8df4594

Browse files
committed
Cleanup
1 parent 0513cb4 commit 8df4594

3 files changed

Lines changed: 19 additions & 40 deletions

File tree

src/agent-client-protocol-core/src/jsonrpc.rs

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,7 +2436,9 @@ impl<Req: JsonRpcRequest, Notif: JsonRpcMessage> Dispatch<Req, Notif> {
24362436
}
24372437
}
24382438

2439-
pub(crate) fn into_handled_no_untyped(
2439+
/// Erase this typed dispatch back to untyped JSON and wrap it in
2440+
/// [`Handled::No`] so the connection loop can offer it to later handlers.
2441+
pub(crate) fn erase_into_unhandled(
24402442
self,
24412443
retry: bool,
24422444
) -> Result<Handled<Dispatch>, crate::Error> {
@@ -2468,24 +2470,6 @@ impl<Req: JsonRpcRequest, Notif: JsonRpcMessage> Dispatch<Req, Notif> {
24682470
}
24692471
}
24702472

2471-
/// Normalize legacy parse errors from matched incoming request/notification params.
2472-
///
2473-
/// `MethodNotFound` still means "this type does not handle the method" and therefore falls
2474-
/// through to later handlers. The SDK's own request/notification parsers now return
2475-
/// `InvalidParams` directly; this rewrite remains only as a compatibility backstop for older
2476-
/// custom parsers that still emit `ParseError`.
2477-
fn normalize_incoming_message_parse_error(err: crate::Error) -> Option<crate::Error> {
2478-
match &err.code {
2479-
crate::ErrorCode::MethodNotFound => None,
2480-
crate::ErrorCode::ParseError => {
2481-
let mut invalid_params = crate::Error::invalid_params();
2482-
invalid_params.data = err.data;
2483-
Some(invalid_params)
2484-
}
2485-
_ => Some(err),
2486-
}
2487-
}
2488-
24892473
/// Outcome of matching an untyped [`Dispatch`] against a request type.
24902474
#[derive(Debug)]
24912475
pub enum RequestMatch<Req: JsonRpcRequest> {
@@ -2546,12 +2530,9 @@ impl Dispatch {
25462530
if Req::matches_method(&message.method) {
25472531
match Req::parse_message(&message.method, &message.params) {
25482532
Ok(req) => RequestMatch::Matched(req, responder.cast()),
2549-
Err(err) => match normalize_incoming_message_parse_error(err) {
2550-
Some(error) => RequestMatch::Rejected {
2551-
dispatch: Dispatch::Request(message, responder),
2552-
error,
2553-
},
2554-
None => RequestMatch::Unhandled(Dispatch::Request(message, responder)),
2533+
Err(error) => RequestMatch::Rejected {
2534+
dispatch: Dispatch::Request(message, responder),
2535+
error,
25552536
},
25562537
}
25572538
} else {
@@ -2575,12 +2556,9 @@ impl Dispatch {
25752556
if Notif::matches_method(&message.method) {
25762557
match Notif::parse_message(&message.method, &message.params) {
25772558
Ok(notif) => NotificationMatch::Matched(notif),
2578-
Err(err) => match normalize_incoming_message_parse_error(err) {
2579-
Some(error) => NotificationMatch::Rejected {
2580-
dispatch: Dispatch::Notification(message),
2581-
error,
2582-
},
2583-
None => NotificationMatch::Unhandled(Dispatch::Notification(message)),
2559+
Err(error) => NotificationMatch::Rejected {
2560+
dispatch: Dispatch::Notification(message),
2561+
error,
25842562
},
25852563
}
25862564
} else {
@@ -2599,6 +2577,7 @@ impl Dispatch {
25992577
/// Once the request/notification side matches by method, any parse error is terminal for
26002578
/// that method and yields [`TypedDispatchMatch::Rejected`]. Likewise, a matched response
26012579
/// whose result cannot be decoded is rejected instead of bubbling up as a fatal `Err`.
2580+
#[must_use]
26022581
pub fn match_typed_dispatch<Req: JsonRpcRequest, Notif: JsonRpcNotification>(
26032582
self,
26042583
) -> TypedDispatchMatch<Req, Notif> {

src/agent-client-protocol-core/src/jsonrpc/handlers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ where
133133
message: (request, responder),
134134
retry,
135135
} => Dispatch::<Req, UntypedMessage>::Request(request, responder)
136-
.into_handled_no_untyped(retry),
136+
.erase_into_unhandled(retry),
137137
}
138138
}
139139
RequestMatch::Unhandled(dispatch) => {
@@ -236,7 +236,7 @@ where
236236
message: (notification, _cx),
237237
retry,
238238
} => Dispatch::<UntypedMessage, Notif>::Notification(notification)
239-
.into_handled_no_untyped(retry),
239+
.erase_into_unhandled(retry),
240240
}
241241
}
242242
NotificationMatch::Unhandled(dispatch) => {
@@ -337,7 +337,7 @@ where
337337
Handled::No {
338338
message: typed_dispatch,
339339
retry,
340-
} => typed_dispatch.into_handled_no_untyped(retry),
340+
} => typed_dispatch.erase_into_unhandled(retry),
341341
}
342342
}
343343
TypedDispatchMatch::Unhandled(dispatch) => Ok(Handled::No {

src/agent-client-protocol-core/src/util/typed.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl MatchDispatch {
115115
message: (request, responder),
116116
retry: request_retry,
117117
} => Dispatch::<Req, UntypedMessage>::Request(request, responder)
118-
.into_handled_no_untyped(retry | request_retry),
118+
.erase_into_unhandled(retry | request_retry),
119119
},
120120
Err(err) => Err(err),
121121
}
@@ -157,7 +157,7 @@ impl MatchDispatch {
157157
message: notification,
158158
retry: notification_retry,
159159
} => Dispatch::<UntypedMessage, N>::Notification(notification)
160-
.into_handled_no_untyped(retry | notification_retry),
160+
.erase_into_unhandled(retry | notification_retry),
161161
},
162162
Err(err) => Err(err),
163163
}
@@ -197,7 +197,7 @@ impl MatchDispatch {
197197
Handled::No {
198198
message: typed_dispatch,
199199
retry: message_retry,
200-
} => match typed_dispatch.into_handled_no_untyped(retry | message_retry) {
200+
} => match typed_dispatch.erase_into_unhandled(retry | message_retry) {
201201
Ok(handled) => Ok(handled),
202202
Err(err) => return Self { state: Err(err) },
203203
},
@@ -259,7 +259,7 @@ impl MatchDispatch {
259259
message: (result, router),
260260
retry: response_retry,
261261
} => Dispatch::<Req, UntypedMessage>::Response(result, router)
262-
.into_handled_no_untyped(retry | response_retry),
262+
.erase_into_unhandled(retry | response_retry),
263263
},
264264
Err(err) => Err(err),
265265
}
@@ -520,7 +520,7 @@ impl<Counterpart: Role> MatchDispatchFrom<Counterpart> {
520520
message: notification,
521521
retry: notification_retry,
522522
} => Dispatch::<UntypedMessage, N>::Notification(notification)
523-
.into_handled_no_untyped(notification_retry),
523+
.erase_into_unhandled(notification_retry),
524524
},
525525
Err(err) => Err(err),
526526
}
@@ -571,7 +571,7 @@ impl<Counterpart: Role> MatchDispatchFrom<Counterpart> {
571571
Handled::No {
572572
message: typed_dispatch,
573573
retry: message_retry,
574-
} => typed_dispatch.into_handled_no_untyped(message_retry),
574+
} => typed_dispatch.erase_into_unhandled(message_retry),
575575
},
576576
Err(err) => Err(err),
577577
},

0 commit comments

Comments
 (0)