Migrate to thiserror (#7177)

* Migrate to thiserror

* Discourage the use of other modules' Result alias

`io::Result` set a bad precedent. Don't import other `Result`
aliases.
This commit is contained in:
Greg Fitzgerald
2019-12-02 15:42:05 -07:00
committed by GitHub
parent f9df17d8d0
commit 6796b08909
20 changed files with 122 additions and 146 deletions

View File

@@ -15,6 +15,7 @@ serde_derive = "1.0.103"
solana-sdk = { path = "../../sdk", version = "0.22.0" }
num-derive = "0.3"
num-traits = "0.2"
thiserror = "1.0"
[dev-dependencies]
solana-runtime = { path = "../../runtime", version = "0.22.0" }

View File

@@ -5,9 +5,11 @@ use solana_sdk::{
pubkey::Pubkey,
system_instruction,
};
use thiserror::Error;
#[derive(Debug, Clone, PartialEq, FromPrimitive, ToPrimitive)]
#[derive(Error, Debug, Clone, PartialEq, FromPrimitive, ToPrimitive)]
pub enum OwnableError {
#[error("incorrect error")]
IncorrectOwner,
}
@@ -17,19 +19,6 @@ impl<T> DecodeError<T> for OwnableError {
}
}
impl std::fmt::Display for OwnableError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
f,
"{}",
match self {
OwnableError::IncorrectOwner => "incorrect owner",
}
)
}
}
impl std::error::Error for OwnableError {}
fn initialize_account(account_pubkey: &Pubkey, owner_pubkey: &Pubkey) -> Instruction {
let keys = vec![AccountMeta::new(*account_pubkey, false)];
Instruction::new(crate::id(), &owner_pubkey, keys)