refactor(protocol): use lost() helper method in adapter (TODO-025 cleanup)
Replace ProtocolError::Lost(msg.to_string()) with ProtocolError::lost(msg) for consistent error construction across the protocol crate.
This commit is contained in:
@@ -299,9 +299,9 @@ impl SnapshotProbe {
|
|||||||
self.tx
|
self.tx
|
||||||
.send(Request::Snapshot(tx))
|
.send(Request::Snapshot(tx))
|
||||||
.await
|
.await
|
||||||
.map_err(|_| ProtocolError::Lost("connection task is gone".to_string()))?;
|
.map_err(|_| ProtocolError::lost("connection task is gone"))?;
|
||||||
rx.await
|
rx.await
|
||||||
.map_err(|_| ProtocolError::Lost("snapshot reply dropped".to_string()))?
|
.map_err(|_| ProtocolError::lost("snapshot reply dropped"))?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,9 +375,9 @@ impl ProtocolClient {
|
|||||||
self.tx
|
self.tx
|
||||||
.send(Request::Snapshot(tx))
|
.send(Request::Snapshot(tx))
|
||||||
.await
|
.await
|
||||||
.map_err(|_| ProtocolError::Lost("connection task is gone".to_string()))?;
|
.map_err(|_| ProtocolError::lost("connection task is gone"))?;
|
||||||
rx.await
|
rx.await
|
||||||
.map_err(|_| ProtocolError::Lost("snapshot reply dropped".to_string()))?
|
.map_err(|_| ProtocolError::lost("snapshot reply dropped"))?
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch richer profile and live connection details for one online client.
|
/// Fetch richer profile and live connection details for one online client.
|
||||||
@@ -389,9 +389,9 @@ impl ProtocolClient {
|
|||||||
reply: tx,
|
reply: tx,
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.map_err(|_| ProtocolError::Lost("connection task is gone".to_string()))?;
|
.map_err(|_| ProtocolError::lost("connection task is gone"))?;
|
||||||
rx.await
|
rx.await
|
||||||
.map_err(|_| ProtocolError::Lost("client_profile reply dropped".to_string()))?
|
.map_err(|_| ProtocolError::lost("client_profile reply dropped"))?
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn download_file(&self, path: String) -> Result<Vec<u8>, ProtocolError> {
|
async fn download_file(&self, path: String) -> Result<Vec<u8>, ProtocolError> {
|
||||||
@@ -399,9 +399,9 @@ impl ProtocolClient {
|
|||||||
self.tx
|
self.tx
|
||||||
.send(Request::DownloadFile { path, reply: tx })
|
.send(Request::DownloadFile { path, reply: tx })
|
||||||
.await
|
.await
|
||||||
.map_err(|_| ProtocolError::Lost("connection task is gone".to_string()))?;
|
.map_err(|_| ProtocolError::lost("connection task is gone"))?;
|
||||||
rx.await
|
rx.await
|
||||||
.map_err(|_| ProtocolError::Lost("download_file reply dropped".to_string()))?
|
.map_err(|_| ProtocolError::lost("download_file reply dropped"))?
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Download the current avatar bytes for a TeamSpeak client UID.
|
/// Download the current avatar bytes for a TeamSpeak client UID.
|
||||||
@@ -450,9 +450,9 @@ impl ProtocolClient {
|
|||||||
reply: tx,
|
reply: tx,
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.map_err(|_| ProtocolError::Lost("connection task is gone".to_string()))?;
|
.map_err(|_| ProtocolError::lost("connection task is gone"))?;
|
||||||
rx.await
|
rx.await
|
||||||
.map_err(|_| ProtocolError::Lost("move_to_channel reply dropped".to_string()))?
|
.map_err(|_| ProtocolError::lost("move_to_channel reply dropped"))?
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Queue a move command and return once it has been accepted by
|
/// Queue a move command and return once it has been accepted by
|
||||||
@@ -469,7 +469,7 @@ impl ProtocolClient {
|
|||||||
password,
|
password,
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.map_err(|_| ProtocolError::Lost("connection task is gone".to_string()))
|
.map_err(|_| ProtocolError::lost("connection task is gone"))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update mute state on our own client. Pass `Some(_)` for the
|
/// Update mute state on our own client. Pass `Some(_)` for the
|
||||||
@@ -487,9 +487,9 @@ impl ProtocolClient {
|
|||||||
reply: tx,
|
reply: tx,
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.map_err(|_| ProtocolError::Lost("connection task is gone".to_string()))?;
|
.map_err(|_| ProtocolError::lost("connection task is gone"))?;
|
||||||
rx.await
|
rx.await
|
||||||
.map_err(|_| ProtocolError::Lost("set_muted reply dropped".to_string()))?
|
.map_err(|_| ProtocolError::lost("set_muted reply dropped"))?
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sender for outbound voice packets. Clone freely.
|
/// Sender for outbound voice packets. Clone freely.
|
||||||
@@ -590,9 +590,9 @@ impl ProtocolClient {
|
|||||||
reply: tx,
|
reply: tx,
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.map_err(|_| ProtocolError::Lost("connection task is gone".to_string()))?;
|
.map_err(|_| ProtocolError::lost("connection task is gone"))?;
|
||||||
rx.await
|
rx.await
|
||||||
.map_err(|_| ProtocolError::Lost("send_text_message reply dropped".to_string()))?
|
.map_err(|_| ProtocolError::lost("send_text_message reply dropped"))?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1171,7 +1171,7 @@ fn move_self_to(
|
|||||||
) -> Result<MessageHandle, ProtocolError> {
|
) -> Result<MessageHandle, ProtocolError> {
|
||||||
let state = con
|
let state = con
|
||||||
.get_state()
|
.get_state()
|
||||||
.map_err(|e| ProtocolError::Backend(format!("get_state: {e}")))?;
|
.map_err(|e| ProtocolError::backend_ctx("get_state", e))?;
|
||||||
let own_id = state.own_client;
|
let own_id = state.own_client;
|
||||||
let own_client = state
|
let own_client = state
|
||||||
.clients
|
.clients
|
||||||
@@ -1184,7 +1184,7 @@ fn move_self_to(
|
|||||||
}
|
}
|
||||||
let handle = part
|
let handle = part
|
||||||
.send_with_result(con)
|
.send_with_result(con)
|
||||||
.map_err(|e| ProtocolError::Backend(format!("client_move send: {e}")))?;
|
.map_err(|e| ProtocolError::backend_ctx("client_move send", e))?;
|
||||||
info!(target: "chanora_protocol", channel_id, "client_move sent");
|
info!(target: "chanora_protocol", channel_id, "client_move sent");
|
||||||
Ok(handle)
|
Ok(handle)
|
||||||
}
|
}
|
||||||
@@ -1202,7 +1202,7 @@ fn set_self_muted(
|
|||||||
let part = {
|
let part = {
|
||||||
let state = con
|
let state = con
|
||||||
.get_state()
|
.get_state()
|
||||||
.map_err(|e| ProtocolError::Backend(format!("get_state: {e}")))?;
|
.map_err(|e| ProtocolError::backend_ctx("get_state", e))?;
|
||||||
let mut p = state.client_update();
|
let mut p = state.client_update();
|
||||||
if let Some(v) = input {
|
if let Some(v) = input {
|
||||||
p = p.set_input_muted(v);
|
p = p.set_input_muted(v);
|
||||||
@@ -1213,7 +1213,7 @@ fn set_self_muted(
|
|||||||
p
|
p
|
||||||
};
|
};
|
||||||
part.send(con)
|
part.send(con)
|
||||||
.map_err(|e| ProtocolError::Backend(format!("client_update send: {e}")))?;
|
.map_err(|e| ProtocolError::backend_ctx("client_update send", e))?;
|
||||||
info!(target: "chanora_protocol", ?input, ?output, "client_update sent");
|
info!(target: "chanora_protocol", ?input, ?output, "client_update sent");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -1239,22 +1239,22 @@ fn send_text_message(
|
|||||||
MessageTarget::Client(client_id) => {
|
MessageTarget::Client(client_id) => {
|
||||||
let state = con
|
let state = con
|
||||||
.get_state()
|
.get_state()
|
||||||
.map_err(|e| ProtocolError::Backend(format!("get_state: {e}")))?;
|
.map_err(|e| ProtocolError::backend_ctx("get_state", e))?;
|
||||||
let client = find_client_by_id(state.clients.values(), client_id)?;
|
let client = find_client_by_id(state.clients.values(), client_id)?;
|
||||||
client
|
client
|
||||||
.send_textmessage(message)
|
.send_textmessage(message)
|
||||||
.send(con)
|
.send(con)
|
||||||
.map_err(|e| ProtocolError::Backend(format!("send_textmessage(client): {e}")))?;
|
.map_err(|e| ProtocolError::backend_ctx("send_textmessage(client)", e))?;
|
||||||
}
|
}
|
||||||
MessageTarget::Poke(client_id) => {
|
MessageTarget::Poke(client_id) => {
|
||||||
let state = con
|
let state = con
|
||||||
.get_state()
|
.get_state()
|
||||||
.map_err(|e| ProtocolError::Backend(format!("get_state: {e}")))?;
|
.map_err(|e| ProtocolError::backend_ctx("get_state", e))?;
|
||||||
let client = find_client_by_id(state.clients.values(), client_id)?;
|
let client = find_client_by_id(state.clients.values(), client_id)?;
|
||||||
client
|
client
|
||||||
.poke(message)
|
.poke(message)
|
||||||
.send(con)
|
.send(con)
|
||||||
.map_err(|e| ProtocolError::Backend(format!("poke: {e}")))?;
|
.map_err(|e| ProtocolError::backend_ctx("poke", e))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
info!(target: "chanora_protocol", len = message.len(), ?target, "text message sent");
|
info!(target: "chanora_protocol", len = message.len(), ?target, "text message sent");
|
||||||
@@ -1275,7 +1275,7 @@ fn send_text_to_mode(
|
|||||||
message: message.into(),
|
message: message.into(),
|
||||||
}))
|
}))
|
||||||
.send(con)
|
.send(con)
|
||||||
.map_err(|e| ProtocolError::Backend(format!("send_textmessage({label}): {e}")))
|
.map_err(|e| ProtocolError::backend_ctx(format!("send_textmessage({label})"), e))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fetch_client_profile(
|
async fn fetch_client_profile(
|
||||||
@@ -1300,7 +1300,7 @@ async fn fetch_client_profile(
|
|||||||
) = {
|
) = {
|
||||||
let state = con
|
let state = con
|
||||||
.get_state()
|
.get_state()
|
||||||
.map_err(|e| ProtocolError::Backend(format!("get_state: {e}")))?;
|
.map_err(|e| ProtocolError::backend_ctx("get_state", e))?;
|
||||||
let client = state
|
let client = state
|
||||||
.clients
|
.clients
|
||||||
.get(&target_id)
|
.get(&target_id)
|
||||||
@@ -1411,7 +1411,7 @@ async fn fetch_client_profile(
|
|||||||
|
|
||||||
let state = con
|
let state = con
|
||||||
.get_state()
|
.get_state()
|
||||||
.map_err(|e| ProtocolError::Backend(format!("get_state: {e}")))?;
|
.map_err(|e| ProtocolError::backend_ctx("get_state", e))?;
|
||||||
let client = state
|
let client = state
|
||||||
.clients
|
.clients
|
||||||
.get(&target_id)
|
.get(&target_id)
|
||||||
@@ -1569,7 +1569,7 @@ async fn request_messages(
|
|||||||
) -> Result<Vec<InMessage>, ProtocolError> {
|
) -> Result<Vec<InMessage>, ProtocolError> {
|
||||||
let handle = command
|
let handle = command
|
||||||
.send_with_result(con)
|
.send_with_result(con)
|
||||||
.map_err(|e| ProtocolError::Backend(format!("send command: {e}")))?;
|
.map_err(|e| ProtocolError::backend_ctx("send command", e))?;
|
||||||
let mut messages = Vec::new();
|
let mut messages = Vec::new();
|
||||||
let deadline = Instant::now() + PROFILE_REFRESH_RESULT_TIMEOUT;
|
let deadline = Instant::now() + PROFILE_REFRESH_RESULT_TIMEOUT;
|
||||||
loop {
|
loop {
|
||||||
@@ -1823,7 +1823,7 @@ fn build_snapshot(
|
|||||||
) -> Result<ServerSnapshot, ProtocolError> {
|
) -> Result<ServerSnapshot, ProtocolError> {
|
||||||
let state: &data::Connection = con
|
let state: &data::Connection = con
|
||||||
.get_state()
|
.get_state()
|
||||||
.map_err(|e| ProtocolError::Backend(format!("get_state: {e}")))?;
|
.map_err(|e| ProtocolError::backend_ctx("get_state", e))?;
|
||||||
|
|
||||||
// TeamSpeak channel ordering: the `order` field on a channel is
|
// TeamSpeak channel ordering: the `order` field on a channel is
|
||||||
// NOT a numeric rank but the id of the channel that should
|
// NOT a numeric rank but the id of the channel that should
|
||||||
|
|||||||
Reference in New Issue
Block a user