Testing: Allow sending error response inside request handler

This commit is contained in:
Remco Smits
2024-12-30 23:17:54 +01:00
parent 7223bf93ba
commit 42d1b484bd
2 changed files with 9 additions and 8 deletions

View File

@@ -263,7 +263,9 @@ impl DebugAdapterClient {
#[cfg(any(test, feature = "test-support"))]
pub async fn on_request<R: dap_types::requests::Request, F>(&self, handler: F)
where
F: 'static + Send + FnMut(u64, R::Arguments) -> Result<R::Response>,
F: 'static
+ Send
+ FnMut(u64, R::Arguments) -> Result<R::Response, dap_types::ErrorResponse>,
{
let transport = self.transport_delegate.transport();

View File

@@ -774,23 +774,22 @@ impl FakeTransport {
pub async fn on_request<R: dap_types::requests::Request, F>(&self, mut handler: F)
where
F: 'static + Send + FnMut(u64, R::Arguments) -> Result<R::Response>,
F: 'static + Send + FnMut(u64, R::Arguments) -> Result<R::Response, ErrorResponse>,
{
self.request_handlers.lock().await.insert(
R::COMMAND,
Box::new(
move |seq, args, writer: Arc<Mutex<async_pipe::PipeWriter>>| {
let response = handler(seq, serde_json::from_value(args).unwrap()).unwrap();
let response = handler(seq, serde_json::from_value(args).unwrap());
let message = Message::Response(Response {
let message = serde_json::to_string(&Message::Response(Response {
seq: seq + 1,
request_seq: seq,
success: true,
success: response.is_ok(),
command: R::COMMAND.into(),
body: Some(serde_json::to_value(response).unwrap()),
});
let message = serde_json::to_string(&message).unwrap();
}))
.unwrap();
let writer = writer.clone();