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:
parent
38713a8e62
commit
2c1972151d
|
|
@ -24,7 +24,7 @@ use crate::profile::Home;
|
||||||
use crate::reactor;
|
use crate::reactor;
|
||||||
use crate::runtime::Emitter;
|
use crate::runtime::Emitter;
|
||||||
use crate::service;
|
use crate::service;
|
||||||
use crate::service::{CommandError, QueryState};
|
use crate::service::QueryState;
|
||||||
use crate::storage::refs::RefsAt;
|
use crate::storage::refs::RefsAt;
|
||||||
use crate::wire;
|
use crate::wire;
|
||||||
use crate::wire::StreamId;
|
use crate::wire::StreamId;
|
||||||
|
|
@ -38,7 +38,7 @@ pub enum Error {
|
||||||
ChannelDisconnected,
|
ChannelDisconnected,
|
||||||
/// The command returned an error.
|
/// The command returned an error.
|
||||||
#[error("command failed: {0}")]
|
#[error("command failed: {0}")]
|
||||||
Command(#[from] CommandError),
|
Command(#[from] service::command::Error),
|
||||||
/// The operation timed out.
|
/// The operation timed out.
|
||||||
#[error("the operation timed out")]
|
#[error("the operation timed out")]
|
||||||
Timeout,
|
Timeout,
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
#![allow(clippy::collapsible_if)]
|
#![allow(clippy::collapsible_if)]
|
||||||
#![warn(clippy::unwrap_used)]
|
#![warn(clippy::unwrap_used)]
|
||||||
pub mod command;
|
pub mod command;
|
||||||
pub use command::{Command, CommandError, QueryState};
|
pub use command::{Command, QueryState};
|
||||||
|
|
||||||
pub mod filter;
|
pub mod filter;
|
||||||
pub mod gossip;
|
pub mod gossip;
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,18 @@ use std::{collections::HashSet, fmt, sync::Arc, time};
|
||||||
|
|
||||||
use crossbeam_channel::Sender;
|
use crossbeam_channel::Sender;
|
||||||
use radicle::crypto::PublicKey;
|
use radicle::crypto::PublicKey;
|
||||||
use radicle::node::policy::config as policy;
|
|
||||||
use radicle::node::policy::Scope;
|
use radicle::node::policy::Scope;
|
||||||
use radicle::node::routing;
|
|
||||||
use radicle::node::FetchResult;
|
use radicle::node::FetchResult;
|
||||||
use radicle::node::Seeds;
|
use radicle::node::Seeds;
|
||||||
use radicle::node::{Address, Alias, Config, ConnectOptions};
|
use radicle::node::{Address, Alias, Config, ConnectOptions};
|
||||||
use radicle::storage;
|
|
||||||
use radicle::storage::refs::RefsAt;
|
use radicle::storage::refs::RefsAt;
|
||||||
use radicle_core::{NodeId, RepoId};
|
use radicle_core::{NodeId, RepoId};
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
use super::ServiceState;
|
use super::ServiceState;
|
||||||
|
|
||||||
/// Function used to query internal service state.
|
/// 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.
|
/// Commands sent to the service by the operator.
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
|
|
@ -47,7 +45,7 @@ pub enum Command {
|
||||||
/// Unfollow the given node.
|
/// Unfollow the given node.
|
||||||
Unfollow(NodeId, Sender<bool>),
|
Unfollow(NodeId, Sender<bool>),
|
||||||
/// Query the internal service state.
|
/// Query the internal service state.
|
||||||
QueryState(Arc<QueryState>, Sender<Result<(), CommandError>>),
|
QueryState(Arc<QueryState>, Sender<Result<(), Error>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Command {
|
impl fmt::Debug for Command {
|
||||||
|
|
@ -71,13 +69,19 @@ impl fmt::Debug for Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Command-related errors.
|
/// An error that occurred when processing a service [`Command`].
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[non_exhaustive]
|
||||||
pub enum CommandError {
|
#[derive(Debug, Error)]
|
||||||
#[error(transparent)]
|
pub enum Error {
|
||||||
Storage(#[from] storage::Error),
|
#[error("{0}")]
|
||||||
#[error(transparent)]
|
Other(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
|
||||||
Routing(#[from] routing::Error),
|
}
|
||||||
#[error(transparent)]
|
|
||||||
Policy(#[from] policy::Error),
|
impl Error {
|
||||||
|
pub(super) fn other<E>(error: E) -> Self
|
||||||
|
where
|
||||||
|
E: std::error::Error + Send + Sync + 'static,
|
||||||
|
{
|
||||||
|
Self::Other(Box::new(error))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue