-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2b973db
commit 772c263
Showing
7 changed files
with
68 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,46 @@ | ||
//! Mollusk errors. These errors will throw a panic. They represent | ||
//! misconfiguration of test inputs or the test environment. | ||
|
||
use { | ||
solana_sdk::pubkey::Pubkey, | ||
std::{fmt::Display, path::Path}, | ||
thiserror::Error, | ||
}; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum MolluskError<'a> { | ||
/// Failed to open file. | ||
#[error("Failed to open file: {0}")] | ||
FileOpenError(&'a Path), | ||
/// Failed to read file. | ||
#[error("Failed to read file: {0}")] | ||
FileReadError(&'a Path), | ||
/// Program file not found. | ||
#[error("Program file not found: {0}")] | ||
FileNotFound(&'a str), | ||
/// An account required by the instruction was not provided. | ||
#[error("An account required by the instruction was not provided: {0}")] | ||
AccountMissing(&'a Pubkey), | ||
/// Program targeted by the instruction is missing from the cache. | ||
#[error("Program targeted by the instruction is missing from the cache: {0}")] | ||
ProgramNotCached(&'a Pubkey), | ||
} | ||
|
||
pub trait MolluskPanic<T> { | ||
fn or_panic_with(self, error: MolluskError) -> T; | ||
} | ||
|
||
impl<T, E> MolluskPanic<T> for Result<T, E> | ||
where | ||
E: Display, | ||
{ | ||
fn or_panic_with(self, mollusk_err: MolluskError) -> T { | ||
self.unwrap_or_else(|err| panic!("{}: {}", mollusk_err, err)) | ||
} | ||
} | ||
|
||
impl<T> MolluskPanic<T> for Option<T> { | ||
fn or_panic_with(self, mollusk_err: MolluskError) -> T { | ||
self.unwrap_or_else(|| panic!("{}", mollusk_err)) | ||
} | ||
} |
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