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 all commits
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
44 changes: 25 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,6 @@ jobs:
- name: Check formatting
run: ./scripts/check-fmt.sh

check:
name: Cargo check
runs-on: ubuntu-latest
needs: [sanity]
steps:
- name: Git Checkout
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/setup
with:
nightly-toolchain: true
cargo-cache-key: cargo-nightly-check
cargo-cache-fallback-key: cargo-nightly

- name: Run checks
run: ./scripts/check-nightly.sh

check-downstream-agave:
if: false # re-enable after agave uses loader-v3-interface v3
name: Cargo check Agave master
Expand Down Expand Up @@ -203,7 +185,7 @@ jobs:
- name: Run semver checks
run: ./scripts/check-semver.sh

hack:
check:
name: Cargo hack check
runs-on: ubuntu-latest
needs: [sanity]
Expand All @@ -226,6 +208,30 @@ jobs:
- name: Run hack check
run: ./scripts/check-hack.sh

powerset:
name: Cargo check powerset
runs-on: ubuntu-latest
needs: [sanity]
steps:
- name: Git Checkout
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/setup
with:
nightly-toolchain: true
clippy: true
cargo-cache-key: cargo-nightly-powerset
cargo-cache-fallback-key: cargo-nightly

- name: Install cargo-hack
uses: taiki-e/cache-cargo-install-action@v2
with:
tool: cargo-hack

- name: Check feature powerset
run: ./scripts/check-powerset.sh

minimal-versions:
name: Check minimal-versions
runs-on: ubuntu-latest
Expand Down
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
3 changes: 1 addition & 2 deletions hash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ pub enum ParseHashError {
Invalid,
}

#[cfg(feature = "std")]
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
7 changes: 2 additions & 5 deletions instruction/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,8 @@ pub enum InstructionError {
// conversions must also be added
}

#[cfg(feature = "std")]
impl std::error::Error for InstructionError {}
impl core::error::Error for InstructionError {}

#[cfg(feature = "std")]
impl fmt::Display for InstructionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Expand Down Expand Up @@ -441,8 +439,7 @@ pub enum LamportsError {
ArithmeticOverflow,
}

#[cfg(feature = "std")]
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
1 change: 1 addition & 0 deletions message/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ frozen-abi = [
"dep:solana-logger",
"solana-hash/frozen-abi",
"solana-pubkey/frozen-abi",
"serde",
]
serde = [
"dep:serde",
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
6 changes: 2 additions & 4 deletions pubkey/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ impl FromPrimitive for PubkeyError {
}
}

#[cfg(feature = "std")]
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 @@ -360,8 +359,7 @@ impl FromPrimitive for ParsePubkeyError {
}
}

#[cfg(feature = "std")]
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 rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.84.1"
channel = "1.85.1"
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
2 changes: 1 addition & 1 deletion scripts/check-hack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ here="$(dirname "$0")"
src_root="$(readlink -f "${here}/..")"
cd "${src_root}"

./cargo nightly hack check --all-targets
./cargo nightly hack check --all-targets --locked --features frozen-abi --ignore-unknown-features
2 changes: 1 addition & 1 deletion scripts/check-nightly.sh → scripts/check-powerset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ here="$(dirname "$0")"
src_root="$(readlink -f "${here}/..")"
cd "${src_root}"

./cargo nightly check --locked --workspace --all-targets --features frozen-abi
./cargo nightly hack clippy --feature-powerset --no-dev-deps -- --deny=warnings
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
24 changes: 12 additions & 12 deletions signature/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Signature error copied directly from RustCrypto's opaque signature error at
//! https://github.com/RustCrypto/traits/tree/master/signature

#[cfg(feature = "alloc")]
#[cfg(all(feature = "std", feature = "alloc"))]
use alloc::boxed::Box;
use core::fmt::{self, Debug, Display};

Expand All @@ -11,19 +11,19 @@ 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
#[derive(Default)]
#[non_exhaustive]
pub struct Error {
/// Source of the error (if applicable).
#[cfg(feature = "std")]
source: Option<Box<dyn std::error::Error + Send + Sync + 'static>>,
#[cfg(all(feature = "std", feature = "alloc"))]
source: Option<Box<dyn core::error::Error + Send + Sync + 'static>>,
}

impl Error {
Expand All @@ -33,9 +33,9 @@ impl Error {
/// errors e.g. signature parsing or verification errors. The intended use
/// cases are for propagating errors related to external signers, e.g.
/// communication/authentication errors with HSMs, KMS, etc.
#[cfg(feature = "std")]
#[cfg(all(feature = "std", feature = "alloc"))]
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 All @@ -44,12 +44,12 @@ impl Error {
}

impl Debug for Error {
#[cfg(not(feature = "std"))]
#[cfg(not(all(feature = "std", feature = "alloc")))]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("signature::Error {}")
}

#[cfg(feature = "std")]
#[cfg(all(feature = "std", feature = "alloc"))]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("signature::Error { source: ")?;

Expand All @@ -69,15 +69,15 @@ impl Display for Error {
}
}

#[cfg(feature = "std")]
impl From<Box<dyn std::error::Error + Send + Sync + 'static>> for Error {
#[cfg(all(feature = "std", feature = "alloc"))]
impl From<Box<dyn core::error::Error + Send + Sync + 'static>> for Error {
fn from(source: Box<dyn std::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
Loading