Skip to content

Replace std::error::Error with core::error::Error #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion address-lookup-table-interface/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum AddressLookupError {
InvalidLookupIndex,
}

impl std::error::Error for AddressLookupError {}
impl core::error::Error for AddressLookupError {}

impl fmt::Display for AddressLookupError {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion commitment-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub enum ParseCommitmentLevelError {
Invalid,
}

impl std::error::Error for ParseCommitmentLevelError {}
impl core::error::Error for ParseCommitmentLevelError {}

impl fmt::Display for ParseCommitmentLevelError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
4 changes: 2 additions & 2 deletions derivation-path/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub enum DerivationPathError {
Infallible,
}

impl std::error::Error for DerivationPathError {}
impl core::error::Error for DerivationPathError {}

impl fmt::Display for DerivationPathError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down Expand Up @@ -224,7 +224,7 @@ const QUERY_KEY_KEY: &str = "key";
#[derive(Clone, Debug, PartialEq, Eq)]
struct QueryKeyError(String);

impl std::error::Error for QueryKeyError {}
impl core::error::Error for QueryKeyError {}

impl fmt::Display for QueryKeyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion hash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub enum ParseHashError {
}

#[cfg(feature = "std")]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess it can be dropped

impl std::error::Error for ParseHashError {}
impl core::error::Error for ParseHashError {}

impl fmt::Display for ParseHashError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
4 changes: 2 additions & 2 deletions instruction/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ pub enum InstructionError {
}

#[cfg(feature = "std")]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one more place

impl std::error::Error for InstructionError {}
impl core::error::Error for InstructionError {}

#[cfg(feature = "std")]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also can be omitted, because this is a core::fmt::Dispalay trait

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I originally considered dropping these attributes, but I wasn't sure. Thank you for confirming.

impl fmt::Display for InstructionError {
Expand Down Expand Up @@ -442,7 +442,7 @@ pub enum LamportsError {
}

#[cfg(feature = "std")]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this one also

impl std::error::Error for LamportsError {}
impl core::error::Error for LamportsError {}

impl fmt::Display for LamportsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion keypair/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ pub fn keypair_from_seed(seed: &[u8]) -> Result<Keypair, Box<dyn error::Error>>
pub fn keypair_from_seed_phrase_and_passphrase(
seed_phrase: &str,
passphrase: &str,
) -> Result<Keypair, Box<dyn std::error::Error>> {
) -> Result<Keypair, Box<dyn core::error::Error>> {
keypair_from_seed(&generate_seed_from_seed_phrase_and_passphrase(
seed_phrase,
passphrase,
Expand Down
2 changes: 1 addition & 1 deletion message/src/compiled_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum CompileError {
UnknownInstructionKey(Pubkey),
}

impl std::error::Error for CompileError {}
impl core::error::Error for CompileError {}

impl fmt::Display for CompileError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion precompile-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl num_traits::ToPrimitive for PrecompileError {
}
}

impl std::error::Error for PrecompileError {}
impl core::error::Error for PrecompileError {}

impl fmt::Display for PrecompileError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
6 changes: 3 additions & 3 deletions program-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub enum ProgramError {
IncorrectAuthority,
}

impl std::error::Error for ProgramError {}
impl core::error::Error for ProgramError {}

impl fmt::Display for ProgramError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down Expand Up @@ -129,14 +129,14 @@ impl fmt::Display for ProgramError {
pub trait PrintProgramError {
fn print<E>(&self)
where
E: 'static + std::error::Error + DecodeError<E> + PrintProgramError + FromPrimitive;
E: 'static + core::error::Error + DecodeError<E> + PrintProgramError + FromPrimitive;
}

#[allow(deprecated)]
impl PrintProgramError for ProgramError {
fn print<E>(&self)
where
E: 'static + std::error::Error + DecodeError<E> + PrintProgramError + FromPrimitive,
E: 'static + core::error::Error + DecodeError<E> + PrintProgramError + FromPrimitive,
{
match self {
Self::Custom(error) => {
Expand Down
4 changes: 2 additions & 2 deletions pubkey/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl FromPrimitive for PubkeyError {
}

#[cfg(feature = "std")]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

impl std::error::Error for PubkeyError {}
impl core::error::Error for PubkeyError {}

impl fmt::Display for PubkeyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down Expand Up @@ -361,7 +361,7 @@ impl FromPrimitive for ParsePubkeyError {
}

#[cfg(feature = "std")]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same here

impl std::error::Error for ParsePubkeyError {}
impl core::error::Error for ParsePubkeyError {}

impl fmt::Display for ParsePubkeyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion quic-definitions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ pub const QUIC_MIN_STAKED_RECEIVE_WINDOW_RATIO: u64 = 128;
pub const QUIC_MAX_STAKED_RECEIVE_WINDOW_RATIO: u64 = 512;

pub trait NotifyKeyUpdate {
fn update_key(&self, key: &Keypair) -> Result<(), Box<dyn std::error::Error>>;
fn update_key(&self, key: &Keypair) -> Result<(), Box<dyn core::error::Error>>;
}
2 changes: 1 addition & 1 deletion sanitize/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A trait for sanitizing values and members of over the wire messages.

use {core::fmt, std::error::Error};
use {core::fmt, core::error::Error};

#[derive(PartialEq, Debug, Eq, Clone)]
pub enum SanitizeError {
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/pubkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub use solana_pubkey::{

#[deprecated(since = "2.1.0")]
#[cfg(feature = "full")]
pub fn write_pubkey_file(outfile: &str, pubkey: Pubkey) -> Result<(), Box<dyn std::error::Error>> {
pub fn write_pubkey_file(outfile: &str, pubkey: Pubkey) -> Result<(), Box<dyn core::error::Error>> {
use std::io::Write;

let printable = format!("{pubkey}");
Expand All @@ -26,7 +26,7 @@ pub fn write_pubkey_file(outfile: &str, pubkey: Pubkey) -> Result<(), Box<dyn st

#[deprecated(since = "2.1.0")]
#[cfg(feature = "full")]
pub fn read_pubkey_file(infile: &str) -> Result<Pubkey, Box<dyn std::error::Error>> {
pub fn read_pubkey_file(infile: &str) -> Result<Pubkey, Box<dyn core::error::Error>> {
let f = std::fs::File::open(infile)?;
let printable: String = serde_json::from_reader(f)?;

Expand Down
2 changes: 1 addition & 1 deletion secp256r1-program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ mod target_arch {
pub fn new_secp256r1_instruction(
message: &[u8],
signing_key: EcKey<Private>,
) -> Result<Instruction, Box<dyn std::error::Error>> {
) -> Result<Instruction, Box<dyn core::error::Error>> {
let group = EcGroup::from_curve_name(Nid::X9_62_PRIME256V1)?;
if signing_key.group().curve_name() != Some(Nid::X9_62_PRIME256V1) {
return Err(("Signing key must be on the secp256r1 curve".to_string()).into());
Expand Down
14 changes: 7 additions & 7 deletions signature/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use core::fmt::{self, Debug, Display};
/// could potentially be used recover signing private keys or forge signatures
/// (e.g. [BB'06]).
///
/// When the `std` feature is enabled, it impls [`std::error::Error`].
/// When the `std` feature is enabled, it impls [`core::error::Error`].
///
/// When the `alloc` feature is enabled, it supports an optional
/// [`std::error::Error::source`], which can be used by things like remote
/// [`core::error::Error::source`], which can be used by things like remote
/// signers (e.g. HSM, KMS) to report I/O or auth errors.
///
/// [BB'06]: https://en.wikipedia.org/wiki/Daniel_Bleichenbacher
Expand All @@ -23,7 +23,7 @@ use core::fmt::{self, Debug, Display};
pub struct Error {
/// Source of the error (if applicable).
#[cfg(feature = "std")]
source: Option<Box<dyn std::error::Error + Send + Sync + 'static>>,
source: Option<Box<dyn core::error::Error + Send + Sync + 'static>>,
}

impl Error {
Expand All @@ -35,7 +35,7 @@ impl Error {
/// communication/authentication errors with HSMs, KMS, etc.
#[cfg(feature = "std")]
pub fn from_source(
source: impl Into<Box<dyn std::error::Error + Send + Sync + 'static>>,
source: impl Into<Box<dyn core::error::Error + Send + Sync + 'static>>,
) -> Self {
Self {
source: Some(source.into()),
Expand Down Expand Up @@ -70,14 +70,14 @@ impl Display for Error {
}

#[cfg(feature = "std")]
impl From<Box<dyn std::error::Error + Send + Sync + 'static>> for Error {
fn from(source: Box<dyn std::error::Error + Send + Sync + 'static>) -> Error {
impl From<Box<dyn core::error::Error + Send + Sync + 'static>> for Error {
fn from(source: Box<dyn core::error::Error + Send + Sync + 'static>) -> Error {
Self::from_source(source)
}
}

#[cfg(feature = "std")]
impl std::error::Error for Error {
impl core::error::Error for Error {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
self.source
.as_ref()
Expand Down
6 changes: 3 additions & 3 deletions signer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub enum PresignerError {
VerificationFailure,
}

impl std::error::Error for PresignerError {}
impl core::error::Error for PresignerError {}

impl fmt::Display for PresignerError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand All @@ -49,8 +49,8 @@ pub enum SignerError {
TooManySigners,
}

impl std::error::Error for SignerError {
fn source(&self) -> ::core::option::Option<&(dyn std::error::Error + 'static)> {
impl core::error::Error for SignerError {
fn source(&self) -> ::core::option::Option<&(dyn core::error::Error + 'static)> {
match self {
Self::KeypairPubkeyMismatch => None,
Self::NotEnoughSigners => None,
Expand Down
12 changes: 6 additions & 6 deletions transaction-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub enum TransactionError {
CommitCancelled,
}

impl std::error::Error for TransactionError {}
impl core::error::Error for TransactionError {}

impl fmt::Display for TransactionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down Expand Up @@ -268,7 +268,7 @@ pub enum AddressLoaderError {
}

#[cfg(not(target_os = "solana"))]
impl std::error::Error for AddressLoaderError {}
impl core::error::Error for AddressLoaderError {}

#[cfg(not(target_os = "solana"))]
impl fmt::Display for AddressLoaderError {
Expand Down Expand Up @@ -314,8 +314,8 @@ pub enum SanitizeMessageError {
}

#[cfg(not(target_os = "solana"))]
impl std::error::Error for SanitizeMessageError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
impl core::error::Error for SanitizeMessageError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::IndexOutOfBounds => None,
Self::ValueOutOfBounds => None,
Expand Down Expand Up @@ -365,8 +365,8 @@ pub enum TransportError {
}

#[cfg(not(target_os = "solana"))]
impl std::error::Error for TransportError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
impl core::error::Error for TransportError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
TransportError::IoError(e) => Some(e),
TransportError::TransactionError(e) => Some(e),
Expand Down
4 changes: 2 additions & 2 deletions vote-interface/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub enum VoteError {
AssertionFailed,
}

impl std::error::Error for VoteError {}
impl core::error::Error for VoteError {}

impl fmt::Display for VoteError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down Expand Up @@ -88,7 +88,7 @@ mod tests {
use num_traits::FromPrimitive;
fn pretty_err<T>(err: InstructionError) -> String
where
T: 'static + std::error::Error + DecodeError<T> + FromPrimitive,
T: 'static + core::error::Error + DecodeError<T> + FromPrimitive,
{
if let InstructionError::Custom(code) = err {
let specific_error: T = T::decode_custom_error_to_enum(code).unwrap();
Expand Down