protocol: opaque command error

Refactor `CommandError` to be an opaque, boxed error.
Rename it to `Error`, so that it is imported via `command::Error`.
This commit is contained in:
Fintan Halpenny 2026-02-13 08:28:27 +00:00 committed by Lorenz Leutgeb
parent 38713a8e62
commit 2c1972151d
3 changed files with 21 additions and 17 deletions

View File

@ -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,

View File

@ -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;

View File

@ -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<bool>),
/// Query the internal service state.
QueryState(Arc<QueryState>, Sender<Result<(), CommandError>>),
QueryState(Arc<QueryState>, Sender<Result<(), Error>>),
}
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<dyn std::error::Error + Send + Sync + 'static>),
}
impl Error {
pub(super) fn other<E>(error: E) -> Self
where
E: std::error::Error + Send + Sync + 'static,
{
Self::Other(Box::new(error))
}
}