Files
FlySimOperationSystem/terminal/src/error.rs
T
lain bbb67a68ab feat(rpc): implement health check service and error handling
- Added `RpcError` enum for comprehensive error handling in RPC operations.
- Introduced `HealthReporter` and `HealthService` for managing service health statuses.
- Implemented health check and watch functionality in the health service.
- Created integration tests for health check service, covering various scenarios.
- Added unit tests for client options validation and stream functionality.
- Established logging infrastructure for terminal and registry components.
- Implemented logging lifecycle management and conflict resolution in tests.
2026-10-09 15:57:35 +08:00

44 lines
1.2 KiB
Rust

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<String>) -> 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()
}
}