Skip to content

Commit

Permalink
Refactor(eth-connector): Use Result return values instead of panicking (
Browse files Browse the repository at this point in the history
  • Loading branch information
birchmd committed Nov 17, 2021
1 parent 736c3ee commit b484c49
Show file tree
Hide file tree
Showing 7 changed files with 722 additions and 319 deletions.
15 changes: 13 additions & 2 deletions engine/src/admin_controlled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@ pub trait AdminControlled {
}

/// Asserts the passed paused flag is not set. Panics with "ERR_PAUSED" if the flag is set.
fn assert_not_paused(&self, flag: PausedMask, is_owner: bool) {
assert!(!self.is_paused(flag, is_owner), "{}", ERR_PAUSED);
fn assert_not_paused(&self, flag: PausedMask, is_owner: bool) -> Result<(), PausedError> {
if self.is_paused(flag, is_owner) {
Err(PausedError)
} else {
Ok(())
}
}
}

pub struct PausedError;
impl AsRef<[u8]> for PausedError {
fn as_ref(&self) -> &[u8] {
ERR_PAUSED.as_bytes()
}
}
Loading

0 comments on commit b484c49

Please sign in to comment.