-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* validate error module refactored - use thiserror and anomaly - rename ValidationError -> validate::Error - rename ValidationErrorKind -> Kind * cleanup Cargo.toml: remove failure and unused feature: - we do not use anomalys serializer feature cleanup Cargo.toml: remove failure and unused feature: - we do not use anomalys serializer feature - remove last place which used failure (looks like we accidentally imported `failure::_core::fmt::Debug` instead of just `std::fmt::Debug` * Address all review comments (thanks @xla) * These are actually validate::Error too
- Loading branch information
Showing
26 changed files
with
163 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,30 @@ | ||
use failure::*; | ||
use thiserror::Error; | ||
|
||
pub trait ConsensusMessage { | ||
fn validate_basic(&self) -> Result<(), ValidationError>; | ||
fn validate_basic(&self) -> Result<(), Error>; | ||
} | ||
|
||
pub struct ValidationError(ValidationErrorKind); | ||
pub type Error = anomaly::BoxError; | ||
|
||
/// Kinds of validation errors | ||
#[derive(Copy, Clone, Eq, PartialEq, Debug, Fail)] | ||
pub enum ValidationErrorKind { | ||
#[fail(display = "invalid Type")] | ||
#[derive(Copy, Clone, Eq, PartialEq, Debug, Error)] | ||
pub enum Kind { | ||
#[error("invalid Type")] | ||
InvalidMessageType, | ||
#[fail(display = "consensus message is missing")] | ||
#[error("consensus message is missing")] | ||
MissingConsensusMessage, | ||
#[fail(display = "negative height")] | ||
#[error("negative height")] | ||
NegativeHeight, | ||
#[fail(display = "negative round")] | ||
#[error("negative round")] | ||
NegativeRound, | ||
#[fail(display = "negative POLRound (exception: -1)")] | ||
#[error("negative POLRound (exception: -1)")] | ||
NegativePOLRound, | ||
#[fail(display = "negative ValidatorIndex")] | ||
#[error("negative ValidatorIndex")] | ||
NegativeValidatorIndex, | ||
#[fail(display = "expected ValidatorAddress size to be 20 bytes")] | ||
#[error("expected ValidatorAddress size to be 20 bytes")] | ||
InvalidValidatorAddressSize, | ||
#[fail(display = "Wrong hash: expected Hash size to be 32 bytes")] | ||
#[error("Wrong hash: expected Hash size to be 32 bytes")] | ||
InvalidHashSize, | ||
#[fail(display = "negative total")] | ||
#[error("negative total")] | ||
NegativeTotal, | ||
} | ||
|
||
impl ToString for ValidationError { | ||
fn to_string(&self) -> String { | ||
self.0.to_string() | ||
} | ||
} | ||
|
||
impl From<ValidationErrorKind> for ValidationError { | ||
fn from(kind: ValidationErrorKind) -> Self { | ||
ValidationError(kind) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.