clementine_core/rpc/
error.rs1use std::fmt::Display;
2use tokio::sync::mpsc::error::SendError;
3use tonic::Status;
4
5pub(crate) fn _expected_msg_got_error(msg: Status) -> Status {
6 Status::invalid_argument(format!("Expected message, got error: {msg}"))
7}
8
9pub(crate) fn expected_msg_got_none(msg: &str) -> impl (Fn() -> Status) + '_ {
10 move || Status::invalid_argument(format!("Expected {msg} but received None"))
11}
12
13pub(crate) fn input_ended_prematurely() -> Status {
14 Status::invalid_argument("Input stream ended prematurely")
15}
16
17pub(crate) fn output_stream_ended_prematurely<T>(e: SendError<T>) -> Status {
18 Status::internal(format!("Output stream ended prematurely: {e}"))
19}
20
21pub(crate) fn invalid_argument<'a, T: std::error::Error + Send + Sync + 'static + Display>(
22 field: &'a str,
23 msg: &'a str,
24) -> impl 'a + Fn(T) -> Status {
25 move |e| Status::invalid_argument(format!("Failed to parse {field}: {msg}\n{e}"))
26}