-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: harmonize dispatch error names #441
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More harmonization required. For a final statement, the document with all runtime existing KILT runtime errors is mandatory (assuming post PR state) as its too easy to oversee stuff.
2edb846
to
788191c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you adjust the PR description? You can remove the parts of the template that don't apply? Also there should be a doc with a description of the naming and conventions? Maybe you could commit that here as a md file?
pallets/did/src/errors.rs
Outdated
} | ||
} | ||
|
||
/// Error involving the pallet's storage. | ||
#[derive(Debug, Eq, PartialEq, TypeInfo)] | ||
pub enum StorageError { | ||
pub enum Storage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason to remove the Error
suffix here? If I see an enum called Storage
I'm not expected error codes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its part of the errors module, so its qualified name is did::errors::Storage which is beautiful. With the suffix it would be did::errors::StorageError.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did::errors::StorageError
would only be used once to bring StorageError
into scope. After that it's always only StorageError
. So your proposal is errors::Storage
vs StorageError
. I personally think StorageError
is better since you can't forget to have the error path. If you don't use errors::Storage
but Storage
this becomes very misleading.
pallets/did/src/errors.rs
Outdated
/// The given DID does not contain the right key to verify the signature | ||
/// of a DID operation. | ||
DidKeyNotPresent(DidVerificationKeyRelationship), | ||
DidKeyNotFound(DidVerificationKeyRelationship), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have NotFound
, KeyNotFound
and DidKeyNotFound
. They all sound very similar.
In case of DidKeyNotFound
, we can't execute the call since the DID doesn't have the required VerificationKeyRelationship
? I would interpret that as disallowing the call and rename it to CallNotAllowed
or similar.
In case of NotFound
and KeyNotFound
I would keep DidNotFound
as it reflects that this is specific for the Did. Best would probably be to have a NotFound(Resource)
error, where the Resource is an enum that contains all the resources that could be missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think now its completely refactored to be in that NotFound(Resource) shape
pallets/did/src/errors.rs
Outdated
@@ -84,7 +84,7 @@ pub enum SignatureError { | |||
/// Error generated when some extrinsic input does not respect the pallet's | |||
/// constraints. | |||
#[derive(Debug, Eq, PartialEq, TypeInfo)] | |||
pub enum InputError { | |||
pub enum Input { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name Input
doesn't reflect that it's error codes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
pallets/did/src/errors.rs
Outdated
} | ||
|
||
/// Error generated when validating a DID operation. | ||
#[derive(Debug, Eq, PartialEq, TypeInfo)] | ||
pub enum SignatureError { | ||
pub enum Signature { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name Signature
doesn't reflect that it's error codes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as with the name of did::errors::Storage, the module indicates that its all about error types
pallets/did/src/errors.rs
Outdated
} | ||
|
||
/// Error generated when validating a DID operation. | ||
#[derive(Debug, Eq, PartialEq, TypeInfo)] | ||
pub enum SignatureError { | ||
pub enum Signature { | ||
/// The signature is not in the format the verification key expects. | ||
InvalidSignatureFormat, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we know it's a signature error, we don't require the Signature in the error name? Same with InvalidSignature
even though we might want to explicitly say that it's the signature part that is wrong and not the nonce part (we also have InvalidNonce
).
InvalidSignatureFormat, | |
InvalidFormat, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the Signature part from the variants and changed from InvalidSignature case to InvalidData
pallets/did/src/service_endpoints.rs
Outdated
@@ -59,48 +59,45 @@ pub struct DidEndpoint<T: Config> { | |||
impl<T: Config> DidEndpoint<T> { | |||
/// Validates a given [DidEndpoint] instance against the constraint | |||
/// set in the pallet's [Config]. | |||
pub(crate) fn validate_against_constraints(&self) -> Result<(), InputError> { | |||
pub(crate) fn validate_against_constraints(&self) -> Result<(), Input> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we would use the errors::Input
path everywhere I would think that this change would make more sense. Seeing only Input
there makes you think that the input is returned in case of an error.
pub(crate) fn validate_against_constraints(&self) -> Result<(), Input> { | |
pub(crate) fn validate_against_constraints(&self) -> Result<(), errors::Input> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pallets/did/src/errors.rs
Outdated
/// See [StorageError]. | ||
StorageError(StorageError), | ||
Storage(Storage), | ||
/// See [SignatureError]. | ||
SignatureError(SignatureError), | ||
Signature(Signature), | ||
/// See [InputError]. | ||
InputError(InputError), | ||
Input(Input), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments need updating
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ntn-x2 What do you think about StorageError
vs errors::Storage
? Which one do you prefer?
pallets/did/src/errors.rs
Outdated
SignatureError(SignatureError), | ||
/// See [InputError]. | ||
InputError(InputError), | ||
pub enum Error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the "no error suffixrule, this would be
Didand not
Error`?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the top-level Error type for DIDs, so calling this Error
in the context of the did::error module kind of makes sense. I agree that this also violates the "no error suffix" rule since technically "Error" is a suffix of "Error", but this is really an edgecase. Naming it "Did" could make sense, but it feels counter-intuitive to me. Perhaps we should modify the no-error suffix rule somehow?
pallets/did/src/did_details.rs
Outdated
.delegation_key | ||
.take() | ||
.ok_or(errors::Storage::NotFound(errors::NotFoundKind::Key( | ||
errors::KeyType::AssertionMethod, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from the name of the function this should be the delegation key?
|
||
/// Enum describing the different did key types. | ||
#[derive(Debug, Eq, PartialEq, TypeInfo)] | ||
pub enum KeyType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even tho this introduces another nesting level i would maybe reuse the DidVerificationKeyRelationship
here.
pub enum KeyType {
Verification(DidVerificationKeyRelationship),
KeyAgreement,
}
You can than implement From<DidVerificationKeyRelationship> for KeyType
or maybe even derive that and From<KeyType> for NotFoundKind
When creating an error gets too deeply nested you can also add a helper function to StorageError
.
My two cents are that types can also be imported directly in Rust. This means that I could do |
I reverted the removal of the Error suffix for the error types in the did::errors module. |
@trusch please fix the CI errors, thanks! |
pallet_error_naming_convention.md
Outdated
|
||
3) Avoid using the pallet name in the variant names. For example instead of "Web3NameNotFound" you should use "NotFound". | ||
|
||
4) Try to take words from the vocabulary already defined in the code base. For example instead of introducing a new variant "NotExisting" you should use, once again, "NotFound" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you list the vocabulary here?
e.g. NotAuthorized, NotFound, AlreadyExists, MaxXYZExceeded (thats all? i guess...)
## fixes KILTprotocol/ticket#2290 This harmonizes the instance names in the Error enums of our pallets. Before this change the names were kind of randomly choosen, so we had for example CTypeNotFound and DidNotPresent. Those names were bad for thwo reasons: 1) They mean the same thing but use different wording 2) They contain the module name After this change both instances would be named NotFound. All the other changes are something along those lines. Co-authored-by: Albrecht <albrecht@kilt.io>
fixes KILTProtocol/ticket#2290
This harmonizes the instance names in the Error enums of our pallets.
Before this change the names were kind of randomly choosen, so we had for example CTypeNotFound and DidNotPresent. Those names were bad for thwo reasons:
After this change both instances would be named NotFound.
All the other changes are something along those lines.
How to test:
Please provide a brief step-by-step instruction.
If necessary provide information about dependencies (specific configuration, branches, database dumps, etc.)
Checklist:
array[3]
useget(3)
, ...)