Skip to content
This repository was archived by the owner on Feb 28, 2021. It is now read-only.

Commit 55c2f5b

Browse files
Merge pull request #374 from radicle-dev/thiserror/registry-error
Thiserror/registry error
2 parents 5892c9d + f078916 commit 55c2f5b

File tree

5 files changed

+36
-47
lines changed

5 files changed

+36
-47
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pub enum CommandError {
151151
/// The subset of possible errors having led a transaction to failure.
152152
#[derive(Debug, ThisError)]
153153
pub enum TransactionError {
154-
#[error("{0}")]
154+
#[error(transparent)]
155155
RegistryError(RegistryError),
156156

157157
#[error("{0:?}")]

core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ std = [
2121
[dependencies]
2222
derive-try-from-primitive = "1.0.0"
2323
rand = { version = "0.7.2", optional = true }
24+
thiserror = "1.0"
2425

2526
[dependencies.parity-scale-codec]
2627
default-features = false

core/src/error.rs

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,66 +17,53 @@ use crate::DispatchError;
1717

1818
use derive_try_from_primitive::TryFromPrimitive;
1919
use std::convert::{TryFrom, TryInto};
20+
use thiserror::Error as ThisError;
2021

21-
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
22+
#[derive(Clone, Copy, Debug, Eq, PartialEq, ThisError, TryFromPrimitive)]
2223
#[repr(u8)]
2324
/// Errors describing failed Registry transactions.
2425
pub enum RegistryError {
26+
#[error("the provided checkpoint does not exist")]
2527
InexistentCheckpointId = 0,
28+
29+
#[error("a registered project must have an initial checkpoint")]
30+
InexistentInitialProjectCheckpoint,
31+
32+
#[error("the provided org does not exist")]
2633
InexistentOrg,
34+
35+
#[error("the provided project does not exist")]
36+
InexistentProjectId,
37+
38+
#[error("the provided user does not exist")]
2739
InexistentUser,
40+
41+
#[error("an org with the same ID already exists")]
2842
DuplicateOrgId,
43+
44+
#[error("a project with the same ID already exists")]
2945
DuplicateProjectId,
46+
47+
#[error("a user with the same ID already exists.")]
3048
DuplicateUserId,
31-
InexistentProjectId,
49+
50+
#[error("the provided fee is insufficient")]
3251
InsufficientFee,
52+
53+
#[error("the sender is not a project member")]
3354
InsufficientSenderPermissions,
34-
InexistentParentCheckpoint,
35-
InexistentInitialProjectCheckpoint,
55+
56+
#[error("the provided checkpoint is not a descendant of the project's initial checkpoint")]
3657
InvalidCheckpointAncestry,
37-
NonUnregisterableUser,
38-
UnregisterableOrg,
39-
UserAccountAssociated,
40-
}
4158

42-
impl From<RegistryError> for &'static str {
43-
fn from(error: RegistryError) -> &'static str {
44-
match error {
45-
RegistryError::InexistentCheckpointId => "The provided checkpoint does not exist",
46-
RegistryError::InexistentOrg => "The provided org does not exist",
47-
RegistryError::InexistentUser => "The provided user does not exist",
48-
RegistryError::DuplicateOrgId => "An org with the same ID already exists.",
49-
RegistryError::DuplicateProjectId => "A project with a similar ID already exists.",
50-
RegistryError::DuplicateUserId => "A user with the same ID already exists.",
51-
RegistryError::InexistentProjectId => "Project does not exist",
52-
RegistryError::InsufficientFee => "The provided fee is insufficient.",
53-
RegistryError::InsufficientSenderPermissions => "Sender is not a project member",
54-
RegistryError::InexistentParentCheckpoint => "Parent checkpoint does not exist",
55-
RegistryError::InexistentInitialProjectCheckpoint => {
56-
"A registered project must have an initial checkpoint."
57-
}
58-
RegistryError::InvalidCheckpointAncestry => {
59-
"The provided checkpoint is not a descendant of the project's initial checkpoint."
60-
}
61-
RegistryError::NonUnregisterableUser => {
62-
"The provided user is not eligible for unregistration."
63-
}
64-
RegistryError::UnregisterableOrg => {
65-
"The provided org is not elibile for unregistration."
66-
}
67-
RegistryError::UserAccountAssociated => {
68-
"The account is already associated with a user."
69-
}
70-
}
71-
}
72-
}
59+
#[error("the provided user is not eligible for unregistration")]
60+
UnregisterableUser,
7361

74-
#[cfg(feature = "std")]
75-
impl core::fmt::Display for RegistryError {
76-
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
77-
let s: &str = self.clone().into();
78-
write!(f, "{}", s)
79-
}
62+
#[error("the provided org is not elibile for unregistration")]
63+
UnregisterableOrg,
64+
65+
#[error("the account is already associated with a user")]
66+
UserAccountAssociated,
8067
}
8168

8269
// The index with which the registry runtime module is declared

runtime/src/registry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ decl_module! {
273273
Ok(())
274274
}
275275
else {
276-
Err(RegistryError::NonUnregisterableUser.into())
276+
Err(RegistryError::UnregisterableUser.into())
277277
}
278278
}
279279
}

0 commit comments

Comments
 (0)