use buffa::MessageField; use buffa_types::google::protobuf::{Any, StringValue}; use proto::control::{InvokeResponse, TerminalEventHandle}; #[derive(Debug, Clone)] pub(crate) struct TerminalError { pub(crate) code: &'static str, pub(crate) message: String, } impl TerminalError { pub(crate) fn new(code: &'static str, message: impl Into) -> Self { Self { code, message: message.into(), } } pub(crate) fn into_response(self) -> InvokeResponse { let error = StringValue { value: format!("{}: {}", self.code, self.message), ..Default::default() }; InvokeResponse { success: false, message: MessageField::some(Any::pack(&error, StringValue::TYPE_URL)), ..Default::default() } } pub(crate) fn display_message(&self) -> String { format!("{}: {}", self.code, self.message) } } pub(crate) fn success_handle(handle: &TerminalEventHandle) -> InvokeResponse { InvokeResponse { success: true, message: MessageField::some(Any::pack(handle, TerminalEventHandle::TYPE_URL)), ..Default::default() } }