From 2c1972151ddad7bd018a913a86bad217a6b753e8 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Fri, 13 Feb 2026 08:28:27 +0000 Subject: [PATCH] protocol: opaque command error Refactor `CommandError` to be an opaque, boxed error. Rename it to `Error`, so that it is imported via `command::Error`. --- crates/radicle-node/src/runtime/handle.rs | 4 +-- crates/radicle-protocol/src/service.rs | 2 +- .../radicle-protocol/src/service/command.rs | 32 +++++++++++-------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/crates/radicle-node/src/runtime/handle.rs b/crates/radicle-node/src/runtime/handle.rs index 391d410b..8675ea81 100644 --- a/crates/radicle-node/src/runtime/handle.rs +++ b/crates/radicle-node/src/runtime/handle.rs @@ -24,7 +24,7 @@ use crate::profile::Home; use crate::reactor; use crate::runtime::Emitter; use crate::service; -use crate::service::{CommandError, QueryState}; +use crate::service::QueryState; use crate::storage::refs::RefsAt; use crate::wire; use crate::wire::StreamId; @@ -38,7 +38,7 @@ pub enum Error { ChannelDisconnected, /// The command returned an error. #[error("command failed: {0}")] - Command(#[from] CommandError), + Command(#[from] service::command::Error), /// The operation timed out. #[error("the operation timed out")] Timeout, diff --git a/crates/radicle-protocol/src/service.rs b/crates/radicle-protocol/src/service.rs index 4cba9ebf..ebbc38b7 100644 --- a/crates/radicle-protocol/src/service.rs +++ b/crates/radicle-protocol/src/service.rs @@ -3,7 +3,7 @@ #![allow(clippy::collapsible_if)] #![warn(clippy::unwrap_used)] pub mod command; -pub use command::{Command, CommandError, QueryState}; +pub use command::{Command, QueryState}; pub mod filter; pub mod gossip; diff --git a/crates/radicle-protocol/src/service/command.rs b/crates/radicle-protocol/src/service/command.rs index be2cab22..4a5f3e5f 100644 --- a/crates/radicle-protocol/src/service/command.rs +++ b/crates/radicle-protocol/src/service/command.rs @@ -2,20 +2,18 @@ use std::{collections::HashSet, fmt, sync::Arc, time}; use crossbeam_channel::Sender; use radicle::crypto::PublicKey; -use radicle::node::policy::config as policy; use radicle::node::policy::Scope; -use radicle::node::routing; use radicle::node::FetchResult; use radicle::node::Seeds; use radicle::node::{Address, Alias, Config, ConnectOptions}; -use radicle::storage; use radicle::storage::refs::RefsAt; use radicle_core::{NodeId, RepoId}; +use thiserror::Error; use super::ServiceState; /// Function used to query internal service state. -pub type QueryState = dyn Fn(&dyn ServiceState) -> Result<(), CommandError> + Send + Sync; +pub type QueryState = dyn Fn(&dyn ServiceState) -> Result<(), Error> + Send + Sync; /// Commands sent to the service by the operator. pub enum Command { @@ -47,7 +45,7 @@ pub enum Command { /// Unfollow the given node. Unfollow(NodeId, Sender), /// Query the internal service state. - QueryState(Arc, Sender>), + QueryState(Arc, Sender>), } impl fmt::Debug for Command { @@ -71,13 +69,19 @@ impl fmt::Debug for Command { } } -/// Command-related errors. -#[derive(thiserror::Error, Debug)] -pub enum CommandError { - #[error(transparent)] - Storage(#[from] storage::Error), - #[error(transparent)] - Routing(#[from] routing::Error), - #[error(transparent)] - Policy(#[from] policy::Error), +/// An error that occurred when processing a service [`Command`]. +#[non_exhaustive] +#[derive(Debug, Error)] +pub enum Error { + #[error("{0}")] + Other(#[source] Box), +} + +impl Error { + pub(super) fn other(error: E) -> Self + where + E: std::error::Error + Send + Sync + 'static, + { + Self::Other(Box::new(error)) + } }