| |
let matching = matching?;
|
| |
|
| |
match matching[..] {
|
| - |
[] => Err(ErgoError::NoRepositoryWithName(wanted.to_string())),
|
| + |
[] => Err(ErgoError::no_repository_with_name(wanted)),
|
| |
[_] => {
|
| |
let repo_id = matching[0];
|
| |
let repo = self.repository(&repo_id)?;
|
| |
Ok(repo)
|
| |
}
|
| - |
[_, _, ..] => Err(ErgoError::NameIsNotUnique(wanted.to_string())),
|
| + |
[_, _, ..] => Err(ErgoError::name_is_not_unique(wanted)),
|
| |
}
|
| |
}
|
| |
|
| |
.profile
|
| |
.home
|
| |
.patches(&repo)
|
| - |
.map_err(|err| ErgoError::LoadPathces(*repo_id, Box::new(err)))?;
|
| + |
.map_err(|err| ErgoError::LoadPatches(*repo_id, Box::new(err)))?;
|
| |
patches
|
| |
.get(patch_id)
|
| - |
.map_err(|err| ErgoError::GetPatch(*repo_id, *patch_id, Box::new(err)))?
|
| - |
.ok_or(ErgoError::NoSuchPatch(*repo_id, *patch_id))
|
| + |
.map_err(|err| ErgoError::get_patch(repo_id, patch_id, err))?
|
| + |
.ok_or(ErgoError::no_such_patch(repo_id, patch_id))
|
| |
}
|
| |
|
| |
/// Resolve a shortened patch ID into a full patch ID.
|
| |
#[derive(Debug, thiserror::Error)]
|
| |
pub enum ErgoError {
|
| |
#[error("failed to load Radicle profile")]
|
| - |
LoadProfile(#[source] radicle::profile::Error),
|
| + |
LoadProfile(#[source] Box<dyn std::error::Error + Send + Sync>),
|
| |
|
| |
#[error("failed to list repositories in Radicle node storage")]
|
| - |
ListRepositories(#[source] radicle::storage::Error),
|
| + |
ListRepositories(#[source] Box<dyn std::error::Error + Send + Sync>),
|
| |
|
| |
#[error("failed to load info from Radicle node storage for repository {0}")]
|
| - |
LoadRepo(RepoId, #[source] Box<radicle::storage::RepositoryError>),
|
| + |
LoadRepo(RepoId, #[source] Box<dyn std::error::Error + Send + Sync>),
|
| |
|
| |
#[error("failed to load project info from Radicle node storage for repository {0}")]
|
| - |
LoadProject(RepoId, #[source] Box<radicle::storage::RepositoryError>),
|
| + |
LoadProject(RepoId, #[source] Box<dyn std::error::Error + Send + Sync>),
|
| |
|
| |
#[error("failed to load patch list from Radicle node storage for repository {0}")]
|
| - |
LoadPathces(RepoId, #[source] Box<radicle::profile::Error>),
|
| + |
LoadPatches(RepoId, #[source] Box<dyn std::error::Error + Send + Sync>),
|
| |
|
| |
#[error("failed to list patches for repository {0}")]
|
| - |
ListCache(RepoId, #[source] radicle::patch::cache::Error),
|
| + |
ListCache(RepoId, #[source] Box<dyn std::error::Error + Send + Sync>),
|
| |
|
| |
#[error("failed to list info for patch {0}")]
|
| - |
CacheListItem(RepoId, #[source] radicle::patch::cache::Error),
|
| + |
CacheListItem(RepoId, #[source] Box<dyn std::error::Error + Send + Sync>),
|
| |
|
| |
#[error("failed to resolve patch id {0:?} in repository {1}")]
|
| - |
ResolvePatchId(String, #[source] radicle::storage::git::raw::Error),
|
| + |
ResolvePatchId(String, #[source] Box<dyn std::error::Error + Send + Sync>),
|
| |
|
| |
#[error("failed to resolve commit id {0:?} in repository {1}")]
|
| - |
ResolveCommit(String, RepoId, #[source] radicle::storage::git::raw::Error),
|
| + |
ResolveCommit(
|
| + |
String,
|
| + |
RepoId,
|
| + |
#[source] Box<dyn std::error::Error + Send + Sync>,
|
| + |
),
|
| |
|
| |
#[error("failed to load patch {1} from Radicle node storage for repository {0}")]
|
| - |
GetPatch(RepoId, PatchId, #[source] Box<radicle::patch::cache::Error>),
|
| + |
GetPatch(
|
| + |
RepoId,
|
| + |
PatchId,
|
| + |
#[source] Box<dyn std::error::Error + Send + Sync>,
|
| + |
),
|
| |
|
| |
#[error("no patch {1} in repository {0}")]
|
| |
NoSuchPatch(RepoId, PatchId),
|
| |
#[error("repository name is not unique: {0:?}")]
|
| |
NameIsNotUnique(String),
|
| |
}
|
| + |
|
| + |
impl ErgoError {
|
| + |
pub(crate) fn load_profile(err: radicle::profile::Error) -> Self {
|
| + |
Self::LoadProfile(Box::new(err))
|
| + |
}
|
| + |
|
| + |
pub(crate) fn list_repositories(err: radicle::storage::Error) -> Self {
|
| + |
Self::ListRepositories(Box::new(err))
|
| + |
}
|
| + |
|
| + |
pub(crate) fn load_repository(id: &RepoId, err: radicle::storage::RepositoryError) -> Self {
|
| + |
Self::LoadRepo(*id, Box::new(err))
|
| + |
}
|
| + |
|
| + |
pub(crate) fn load_project(id: &RepoId, err: radicle::storage::RepositoryError) -> Self {
|
| + |
Self::LoadRepo(*id, Box::new(err))
|
| + |
}
|
| + |
|
| + |
pub(crate) fn load_patches(id: &RepoId, err: radicle::profile::Error) -> Self {
|
| + |
Self::LoadPatches(*id, Box::new(err))
|
| + |
}
|
| + |
|
| + |
pub(crate) fn list_cache(id: &RepoId, err: radicle::patch::cache::Error) -> Self {
|
| + |
Self::ListCache(*id, Box::new(err))
|
| + |
}
|
| + |
|
| + |
pub(crate) fn cache_list_item(id: &RepoId, err: radicle::patch::cache::Error) -> Self {
|
| + |
Self::CacheListItem(*id, Box::new(err))
|
| + |
}
|
| + |
|
| + |
pub(crate) fn resolve_patch_id<S: Into<String>>(
|
| + |
id: S,
|
| + |
err: radicle::storage::git::raw::Error,
|
| + |
) -> Self {
|
| + |
Self::ResolvePatchId(id.into(), Box::new(err))
|
| + |
}
|
| + |
|
| + |
pub(crate) fn resolve_commit<S: Into<String>>(
|
| + |
commit: S,
|
| + |
repo: &RepoId,
|
| + |
err: radicle::storage::git::raw::Error,
|
| + |
) -> Self {
|
| + |
Self::ResolveCommit(commit.into(), *repo, Box::new(err))
|
| + |
}
|
| + |
|
| + |
pub(crate) fn get_patch(
|
| + |
repo: &RepoId,
|
| + |
patch: &PatchId,
|
| + |
err: radicle::patch::cache::Error,
|
| + |
) -> Self {
|
| + |
Self::GetPatch(*repo, *patch, Box::new(err))
|
| + |
}
|
| + |
|
| + |
pub(crate) fn no_such_patch(repo: &RepoId, patch: &PatchId) -> Self {
|
| + |
Self::NoSuchPatch(*repo, *patch)
|
| + |
}
|
| + |
|
| + |
pub(crate) fn no_repository_with_name<S: Into<String>>(name: S) -> Self {
|
| + |
Self::NoRepositoryWithName(name.into())
|
| + |
}
|
| + |
|
| + |
pub(crate) fn name_is_not_unique<S: Into<String>>(name: S) -> Self {
|
| + |
Self::NameIsNotUnique(name.into())
|
| + |
}
|
| + |
}
|