-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(driver): Allow the driver to raise errors in some occasions (#62)
* feat(driver): Allow the driver to raise errors in some occasions * Allow test env to not supply a value * Exclude some standard instances from code coverage * Add unit tests for error cases
- Loading branch information
Showing
10 changed files
with
326 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use core::fmt; | ||
|
||
use malachite_common::{Context, SignedVote, Validator}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub enum Error<Ctx> | ||
where | ||
Ctx: Context, | ||
{ | ||
/// No value to propose | ||
NoValueToPropose, | ||
|
||
/// Proposer not found | ||
ProposerNotFound(Ctx::Address), | ||
|
||
/// Validator not found in validator set | ||
ValidatorNotFound(Ctx::Address), | ||
|
||
/// Invalid vote signature | ||
InvalidVoteSignature(SignedVote<Ctx>, Ctx::Validator), | ||
} | ||
|
||
impl<Ctx> fmt::Display for Error<Ctx> | ||
where | ||
Ctx: Context, | ||
{ | ||
#[cfg_attr(coverage_nightly, coverage(off))] | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Error::NoValueToPropose => write!(f, "No value to propose"), | ||
Error::ProposerNotFound(addr) => write!(f, "Proposer not found: {addr}"), | ||
Error::ValidatorNotFound(addr) => write!(f, "Validator not found: {addr}"), | ||
Error::InvalidVoteSignature(vote, validator) => write!( | ||
f, | ||
"Invalid vote signature by {} on vote {vote:?}", | ||
validator.address() | ||
), | ||
} | ||
} | ||
} | ||
|
||
impl<Ctx> PartialEq for Error<Ctx> | ||
where | ||
Ctx: Context, | ||
{ | ||
#[cfg_attr(coverage_nightly, coverage(off))] | ||
fn eq(&self, other: &Self) -> bool { | ||
match (self, other) { | ||
(Error::NoValueToPropose, Error::NoValueToPropose) => true, | ||
(Error::ProposerNotFound(addr1), Error::ProposerNotFound(addr2)) => addr1 == addr2, | ||
(Error::ValidatorNotFound(addr1), Error::ValidatorNotFound(addr2)) => addr1 == addr2, | ||
( | ||
Error::InvalidVoteSignature(vote1, validator1), | ||
Error::InvalidVoteSignature(vote2, validator2), | ||
) => vote1 == vote2 && validator1 == validator2, | ||
_ => false, | ||
} | ||
} | ||
} |
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
Oops, something went wrong.