mcfunction_debug_adapter/
error.rs1use debug_adapter_protocol::{
20 responses::{ErrorResponse, ErrorResponseBody},
21 types::Message as ErrorMessage,
22};
23use std::io;
24
25#[derive(Debug)]
26pub enum DebugAdapterError<I, O, C> {
27 Input(I),
28 Output(O),
29 Custom(C),
30}
31impl<E> DebugAdapterError<E, E, E> {
32 pub fn into_inner(self) -> E {
33 match self {
34 DebugAdapterError::Input(e) => e,
35 DebugAdapterError::Output(e) => e,
36 DebugAdapterError::Custom(e) => e,
37 }
38 }
39}
40
41pub enum RequestError<C> {
42 Terminate(C),
43 Respond(PartialErrorResponse),
44}
45impl<C> From<PartialErrorResponse> for RequestError<C> {
46 fn from(error: PartialErrorResponse) -> Self {
47 Self::Respond(error)
48 }
49}
50
51pub struct PartialErrorResponse {
52 pub message: String,
53 pub details: Option<ErrorMessage>,
54}
55
56impl PartialErrorResponse {
57 pub fn new(message: String) -> PartialErrorResponse {
58 PartialErrorResponse {
59 message,
60 details: None,
61 }
62 }
63
64 pub fn with_command(self, command: String) -> ErrorResponse {
65 ErrorResponse::builder()
66 .command(command)
67 .message(self.message)
68 .body(ErrorResponseBody::new(self.details))
69 .build()
70 }
71}
72
73impl From<io::Error> for PartialErrorResponse {
74 fn from(error: io::Error) -> Self {
75 Self {
76 message: error.to_string(),
77 details: None,
78 }
79 }
80}