From 65fcb316790f514ff897b23332966e347cb5a3e7 Mon Sep 17 00:00:00 2001
From: Pavlo Khrystenko
Date: Wed, 6 Nov 2024 13:19:26 +0100
Subject: [PATCH 1/5] Migrate to thiserror
---
Cargo.lock | 223 ++++++++++--------
Cargo.toml | 2 +-
core/Cargo.toml | 3 +
.../src/blocks/extrinsic_signed_extensions.rs | 3 +-
core/src/blocks/extrinsics.rs | 3 +-
core/src/error.rs | 205 ++++------------
core/src/events.rs | 3 +-
core/src/macros.rs | 10 -
core/src/storage/storage_key.rs | 4 +-
core/src/utils/account_id.rs | 23 +-
core/src/utils/account_id20.rs | 21 +-
metadata/Cargo.toml | 1 +
metadata/src/from_into/mod.rs | 37 +--
signer/Cargo.toml | 1 +
signer/src/ecdsa.rs | 30 +--
signer/src/eth.rs | 23 +-
signer/src/polkadot_js_compat.rs | 44 ++--
signer/src/sr25519.rs | 32 +--
18 files changed, 245 insertions(+), 423 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 113d639815..ed1bd95669 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -152,7 +152,7 @@ dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
"syn-solidity",
"tiny-keccak",
]
@@ -249,7 +249,7 @@ dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -794,7 +794,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -817,7 +817,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -1422,7 +1422,7 @@ dependencies = [
"semver 1.0.22",
"serde",
"serde_json",
- "thiserror",
+ "thiserror 1.0.64",
]
[[package]]
@@ -1549,7 +1549,7 @@ dependencies = [
"heck 0.5.0",
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -2067,7 +2067,7 @@ dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -2299,7 +2299,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -2326,7 +2326,7 @@ dependencies = [
"proc-macro2",
"quote",
"scratch",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -2343,7 +2343,7 @@ checksum = "98532a60dedaebc4848cb2cba5023337cc9ea3af16a5b062633fabfd9f18fb60"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -2367,7 +2367,7 @@ dependencies = [
"proc-macro2",
"quote",
"strsim",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -2378,7 +2378,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806"
dependencies = [
"darling_core",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -2419,7 +2419,7 @@ checksum = "d65d7ce8132b7c0e54497a4d9a55a1c2a0912a0d786cf894472ba818fba45762"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -2430,7 +2430,7 @@ checksum = "62d671cc41a825ebabc75757b62d3d168c577f9149b2d49ece1dad1f72119d25"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -2463,7 +2463,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
"unicode-xid",
]
@@ -2536,7 +2536,7 @@ dependencies = [
"proc-macro2",
"quote",
"regex",
- "syn 2.0.77",
+ "syn 2.0.87",
"termcolor",
"toml 0.8.12",
"walkdir",
@@ -2684,7 +2684,7 @@ checksum = "de0d48a183585823424a4ce1aa132d174a6a81bd540895822eb4c8373a8e49e8"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -2695,7 +2695,7 @@ checksum = "2f9ed6b3789237c8a0c1c505af1c7eb2c560df6186f01b098c3a1064ea532f38"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -2827,7 +2827,7 @@ dependencies = [
"prettier-please",
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -3023,7 +3023,7 @@ dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -3162,7 +3162,7 @@ dependencies = [
"proc-macro2",
"quote",
"sp-crypto-hashing",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -3175,7 +3175,7 @@ dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -3186,7 +3186,7 @@ checksum = "ed971c6435503a099bdac99fe4c5bea08981709e5b5a0a8535a1856f48561191"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -3333,7 +3333,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -3486,7 +3486,7 @@ dependencies = [
"pin-project",
"serde",
"serde_json",
- "thiserror",
+ "thiserror 1.0.64",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
@@ -3979,7 +3979,7 @@ dependencies = [
"subxt-metadata",
"subxt-signer",
"subxt-test-macro",
- "syn 2.0.77",
+ "syn 2.0.87",
"test-runtime",
"tokio",
"tracing",
@@ -4052,7 +4052,7 @@ dependencies = [
"combine",
"jni-sys",
"log",
- "thiserror",
+ "thiserror 1.0.64",
"walkdir",
]
@@ -4113,7 +4113,7 @@ dependencies = [
"rustls-pki-types",
"rustls-platform-verifier",
"soketto",
- "thiserror",
+ "thiserror 1.0.64",
"tokio",
"tokio-rustls",
"tokio-util",
@@ -4141,7 +4141,7 @@ dependencies = [
"rustc-hash 2.0.0",
"serde",
"serde_json",
- "thiserror",
+ "thiserror 1.0.64",
"tokio",
"tokio-stream",
"tracing",
@@ -4166,7 +4166,7 @@ dependencies = [
"rustls-platform-verifier",
"serde",
"serde_json",
- "thiserror",
+ "thiserror 1.0.64",
"tokio",
"tower",
"tracing",
@@ -4192,7 +4192,7 @@ dependencies = [
"serde",
"serde_json",
"soketto",
- "thiserror",
+ "thiserror 1.0.64",
"tokio",
"tokio-stream",
"tokio-util",
@@ -4209,7 +4209,7 @@ dependencies = [
"http",
"serde",
"serde_json",
- "thiserror",
+ "thiserror 1.0.64",
]
[[package]]
@@ -4427,7 +4427,7 @@ dependencies = [
"macro_magic_core",
"macro_magic_macros",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -4441,7 +4441,7 @@ dependencies = [
"macro_magic_core_macros",
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -4452,7 +4452,7 @@ checksum = "b02abfe41815b5bd98dbd4260173db2c116dda171dc0fe7838cb206333b83308"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -4463,7 +4463,7 @@ checksum = "73ea28ee64b88876bf45277ed9a5817c1817df061a74f2b988971a12570e5869"
dependencies = [
"macro_magic_core",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -4587,7 +4587,7 @@ checksum = "254a5372af8fc138e36684761d3c0cdb758a4410e938babcff1c860ce14ddbfc"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -4656,7 +4656,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -5356,7 +5356,7 @@ checksum = "94226cbd48516b7c310eb5dae8d50798c1ce73a7421dc0977c55b7fc2237a283"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -6162,7 +6162,7 @@ checksum = "0cc16d1f7cee6a1ee6e8cd710e16230d59fb4935316c1704cf770e4d2335f8d4"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -6934,7 +6934,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdbef9d1d47087a895abd220ed25eb4ad973a5e26f6a4367b038c25e28dfc2d9"
dependencies = [
"memchr",
- "thiserror",
+ "thiserror 1.0.64",
"ucd-trie",
]
@@ -6955,7 +6955,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -7587,7 +7587,7 @@ dependencies = [
"polkavm-common 0.9.0",
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -7599,7 +7599,7 @@ dependencies = [
"polkavm-common 0.10.0",
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -7609,7 +7609,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ba81f7b5faac81e528eb6158a6f3c9e0bb1008e0ffa19653bc8dea925ecb429"
dependencies = [
"polkavm-derive-impl 0.9.0",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -7619,7 +7619,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9324fe036de37c17829af233b46ef6b5562d4a0c09bb7fdb9f8378856dee30cf"
dependencies = [
"polkavm-derive-impl 0.10.0",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -7721,7 +7721,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22020dfcf177fcc7bf5deaf7440af371400c67c0de14c399938d8ed4fb4645d3"
dependencies = [
"proc-macro2",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -7813,7 +7813,7 @@ dependencies = [
"proc-macro-error-attr2",
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -7824,7 +7824,7 @@ checksum = "834da187cfe638ae8abb0203f0b33e5ccdb02a28e7199f2f47b3e2754f50edca"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -7977,7 +7977,7 @@ checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
dependencies = [
"getrandom",
"libredox",
- "thiserror",
+ "thiserror 1.0.64",
]
[[package]]
@@ -7997,7 +7997,7 @@ checksum = "5fddb4f8d99b0a2ebafc65a87a69a7b9875e4b1ae1f00db265d300ef7f28bccc"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -8405,7 +8405,7 @@ dependencies = [
"log",
"sp-core",
"sp-wasm-interface",
- "thiserror",
+ "thiserror 1.0.64",
]
[[package]]
@@ -8442,7 +8442,7 @@ dependencies = [
"sc-allocator",
"sp-maybe-compressed-blob",
"sp-wasm-interface",
- "thiserror",
+ "thiserror 1.0.64",
"wasm-instrument",
]
@@ -8513,7 +8513,7 @@ dependencies = [
"darling",
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -8541,7 +8541,7 @@ dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -8589,8 +8589,8 @@ dependencies = [
"proc-macro2",
"quote",
"scale-info",
- "syn 2.0.77",
- "thiserror",
+ "syn 2.0.87",
+ "thiserror 1.0.64",
]
[[package]]
@@ -8887,7 +8887,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -9529,7 +9529,7 @@ dependencies = [
"sp-state-machine",
"sp-trie",
"sp-version",
- "thiserror",
+ "thiserror 1.0.64",
]
[[package]]
@@ -9544,7 +9544,7 @@ dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -9741,7 +9741,7 @@ dependencies = [
"sp-storage",
"ss58-registry",
"substrate-bip39",
- "thiserror",
+ "thiserror 1.0.64",
"tracing",
"w3f-bls",
"zeroize",
@@ -9799,7 +9799,7 @@ checksum = "b85d0f1f1e44bd8617eb2a48203ee854981229e3e79e6f468c7175d5fd37489b"
dependencies = [
"quote",
"sp-crypto-hashing",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -9810,7 +9810,7 @@ checksum = "48d09fa0a5f7299fb81ee25ae3853d26200f7a348148aed6de76be905c007dbe"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -9848,7 +9848,7 @@ dependencies = [
"parity-scale-codec",
"scale-info",
"sp-runtime",
- "thiserror",
+ "thiserror 1.0.64",
]
[[package]]
@@ -9907,7 +9907,7 @@ version = "11.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0c768c11afbe698a090386876911da4236af199cd38a5866748df4d8628aeff"
dependencies = [
- "thiserror",
+ "thiserror 1.0.64",
"zstd 0.12.4",
]
@@ -9949,7 +9949,7 @@ dependencies = [
"sp-core",
"sp-debug-derive",
"sp-runtime",
- "thiserror",
+ "thiserror 1.0.64",
]
[[package]]
@@ -10046,7 +10046,7 @@ dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -10108,7 +10108,7 @@ dependencies = [
"sp-externalities",
"sp-panic-handler",
"sp-trie",
- "thiserror",
+ "thiserror 1.0.64",
"tracing",
"trie-db",
]
@@ -10134,7 +10134,7 @@ dependencies = [
"sp-externalities",
"sp-runtime",
"sp-runtime-interface",
- "thiserror",
+ "thiserror 1.0.64",
"x25519-dalek",
]
@@ -10167,7 +10167,7 @@ dependencies = [
"parity-scale-codec",
"sp-inherents",
"sp-runtime",
- "thiserror",
+ "thiserror 1.0.64",
]
[[package]]
@@ -10225,7 +10225,7 @@ dependencies = [
"schnellru",
"sp-core",
"sp-externalities",
- "thiserror",
+ "thiserror 1.0.64",
"tracing",
"trie-db",
"trie-root",
@@ -10246,7 +10246,7 @@ dependencies = [
"sp-runtime",
"sp-std",
"sp-version-proc-macro",
- "thiserror",
+ "thiserror 1.0.64",
]
[[package]]
@@ -10258,7 +10258,7 @@ dependencies = [
"parity-scale-codec",
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -10497,7 +10497,7 @@ dependencies = [
"proc-macro2",
"quote",
"rustversion",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -10577,7 +10577,7 @@ dependencies = [
"subxt-macro",
"subxt-metadata",
"subxt-signer",
- "thiserror",
+ "thiserror 2.0.0",
"tokio",
"tokio-util",
"tower",
@@ -10613,8 +10613,8 @@ dependencies = [
"subxt-codegen",
"subxt-metadata",
"subxt-utils-fetchmetadata",
- "syn 2.0.77",
- "thiserror",
+ "syn 2.0.87",
+ "thiserror 2.0.0",
"tokio",
]
@@ -10631,8 +10631,8 @@ dependencies = [
"scale-info",
"scale-typegen",
"subxt-metadata",
- "syn 2.0.77",
- "thiserror",
+ "syn 2.0.87",
+ "thiserror 2.0.0",
]
[[package]]
@@ -10663,6 +10663,7 @@ dependencies = [
"subxt-macro",
"subxt-metadata",
"subxt-signer",
+ "thiserror 2.0.0",
"tracing",
]
@@ -10681,7 +10682,7 @@ dependencies = [
"serde_json",
"smoldot",
"smoldot-light",
- "thiserror",
+ "thiserror 2.0.0",
"tokio",
"tokio-stream",
"tracing",
@@ -10703,7 +10704,7 @@ dependencies = [
"scale-typegen",
"subxt-codegen",
"subxt-utils-fetchmetadata",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -10718,6 +10719,7 @@ dependencies = [
"parity-scale-codec",
"polkadot-sdk",
"scale-info",
+ "thiserror 2.0.0",
]
[[package]]
@@ -10747,6 +10749,7 @@ dependencies = [
"serde_json",
"sha2 0.10.8",
"subxt-core",
+ "thiserror 2.0.0",
"zeroize",
]
@@ -10755,7 +10758,7 @@ name = "subxt-test-macro"
version = "0.38.0"
dependencies = [
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -10766,7 +10769,7 @@ dependencies = [
"hex",
"jsonrpsee",
"parity-scale-codec",
- "thiserror",
+ "thiserror 2.0.0",
"tokio",
"url",
]
@@ -10784,9 +10787,9 @@ dependencies = [
[[package]]
name = "syn"
-version = "2.0.77"
+version = "2.0.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed"
+checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d"
dependencies = [
"proc-macro2",
"quote",
@@ -10802,7 +10805,7 @@ dependencies = [
"paste",
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -10888,7 +10891,16 @@ version = "1.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84"
dependencies = [
- "thiserror-impl",
+ "thiserror-impl 1.0.64",
+]
+
+[[package]]
+name = "thiserror"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "15291287e9bff1bc6f9ff3409ed9af665bec7a5fc8ac079ea96be07bca0e2668"
+dependencies = [
+ "thiserror-impl 2.0.0",
]
[[package]]
@@ -10899,7 +10911,18 @@ checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
+]
+
+[[package]]
+name = "thiserror-impl"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "22efd00f33f93fa62848a7cab956c3d38c8d43095efda1decfc2b3a5dc0b8972"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.87",
]
[[package]]
@@ -11001,7 +11024,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -11143,7 +11166,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -11435,7 +11458,7 @@ dependencies = [
"rand_core",
"sha2 0.10.8",
"sha3",
- "thiserror",
+ "thiserror 1.0.64",
"zeroize",
]
@@ -11518,7 +11541,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
"wasm-bindgen-shared",
]
@@ -11552,7 +11575,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@@ -11583,7 +11606,7 @@ dependencies = [
"strum 0.24.1",
"strum_macros 0.24.3",
"tempfile",
- "thiserror",
+ "thiserror 1.0.64",
"wasm-opt-cxx-sys",
"wasm-opt-sys",
]
@@ -11744,7 +11767,7 @@ dependencies = [
"log",
"object 0.30.4",
"target-lexicon",
- "thiserror",
+ "thiserror 1.0.64",
"wasmparser",
"wasmtime-cranelift-shared",
"wasmtime-environ",
@@ -11779,7 +11802,7 @@ dependencies = [
"object 0.30.4",
"serde",
"target-lexicon",
- "thiserror",
+ "thiserror 1.0.64",
"wasmparser",
"wasmtime-types",
]
@@ -11862,7 +11885,7 @@ checksum = "a4f6fffd2a1011887d57f07654dd112791e872e3ff4a2e626aee8059ee17f06f"
dependencies = [
"cranelift-entity",
"serde",
- "thiserror",
+ "thiserror 1.0.64",
"wasmparser",
]
@@ -12224,7 +12247,7 @@ dependencies = [
"Inflector",
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -12294,7 +12317,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
@@ -12314,7 +12337,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.77",
+ "syn 2.0.87",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 7180e2a7e4..1b15c0da5d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -103,7 +103,7 @@ scale-typegen-description = "0.9.0"
serde = { version = "1.0.210", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.128", default-features = false }
syn = { version = "2.0.77", features = ["full", "extra-traits"] }
-thiserror = "1.0.64"
+thiserror = { version = "2.0.0", default-features = false }
tokio = { version = "1.40", default-features = false }
tracing = { version = "0.1.40", default-features = false }
tracing-wasm = "0.2.1"
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 17c73a89e5..0aba388510 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -65,6 +65,9 @@ tracing = { workspace = true, default-features = false }
# AccountId20
keccak-hash = { workspace = true}
+# Error handling
+thiserror = { workspace = true, default-features = false }
+
[dev-dependencies]
assert_matches = { workspace = true }
bitvec = { workspace = true }
diff --git a/core/src/blocks/extrinsic_signed_extensions.rs b/core/src/blocks/extrinsic_signed_extensions.rs
index 4731cba6b0..8be6c3308f 100644
--- a/core/src/blocks/extrinsic_signed_extensions.rs
+++ b/core/src/blocks/extrinsic_signed_extensions.rs
@@ -120,7 +120,8 @@ impl<'a, T: Config> ExtrinsicSignedExtension<'a, T> {
&mut &self.bytes[..],
self.ty_id,
self.metadata.types(),
- )?;
+ )
+ .map_err(Into::::into)?;
Ok(value)
}
diff --git a/core/src/blocks/extrinsics.rs b/core/src/blocks/extrinsics.rs
index ac58ab87f4..52d945de95 100644
--- a/core/src/blocks/extrinsics.rs
+++ b/core/src/blocks/extrinsics.rs
@@ -287,7 +287,8 @@ where
.iter()
.map(|f| scale_decode::Field::new(f.ty.id, f.name.as_deref()));
let decoded =
- scale_value::scale::decode_as_fields(bytes, &mut fields, self.metadata.types())?;
+ scale_value::scale::decode_as_fields(bytes, &mut fields, self.metadata.types())
+ .map_err(Into::::into)?;
Ok(decoded)
}
diff --git a/core/src/error.rs b/core/src/error.rs
index 000a3019cc..efaf448139 100644
--- a/core/src/error.rs
+++ b/core/src/error.rs
@@ -4,61 +4,42 @@
//! The errors that can be emitted in this crate.
-use core::fmt::Display;
-
use alloc::boxed::Box;
use alloc::string::String;
use subxt_metadata::StorageHasher;
+use thiserror::Error as DeriveError;
/// The error emitted when something goes wrong.
-#[derive(Debug)]
+#[derive(Debug, DeriveError)]
pub enum Error {
/// Codec error.
- Codec(codec::Error),
+ #[error("Scale codec error: {0}")]
+ Codec(#[from] codec::Error),
/// Metadata error.
- Metadata(MetadataError),
+ #[error("Metadata Error: {0}")]
+ Metadata(#[from] MetadataError),
/// Storage address error.
- StorageAddress(StorageAddressError),
+ #[error("Storage Error: {0}")]
+ StorageAddress(#[from] StorageAddressError),
/// Error decoding to a [`crate::dynamic::Value`].
- Decode(scale_decode::Error),
+ #[error("Error decoding into dynamic value: {0}")]
+ Decode(#[from] scale_decode::Error),
/// Error encoding from a [`crate::dynamic::Value`].
- Encode(scale_encode::Error),
+ #[error("Error encoding from dynamic value: {0}")]
+ Encode(#[from] scale_encode::Error),
/// Error constructing the appropriate extrinsic params.
- ExtrinsicParams(ExtrinsicParamsError),
+ #[error("Extrinsic params error: {0}")]
+ ExtrinsicParams(#[from] ExtrinsicParamsError),
/// Block body error.
- Block(BlockError),
-}
-
-impl core::fmt::Display for Error {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- match self {
- Error::Codec(e) => write!(f, "Scale codec error: {e}"),
- Error::Metadata(e) => write!(f, "Metadata Error: {e}"),
- Error::StorageAddress(e) => write!(f, "Storage Error: {e}"),
- Error::Decode(e) => write!(f, "Error decoding into dynamic value: {e}"),
- Error::Encode(e) => write!(f, "Error encoding from dynamic value: {e}"),
- Error::ExtrinsicParams(e) => write!(f, "Extrinsic params error: {e}"),
- Error::Block(e) => write!(f, "Error working with block_body: {}", e),
- }
- }
+ #[error("Error working with block_body: {0}")]
+ Block(#[from] BlockError),
}
-#[cfg(feature = "std")]
-impl std::error::Error for Error {}
-
-impl_from!(ExtrinsicParamsError => Error::ExtrinsicParams);
-impl_from!(BlockError => Error::Block);
-impl_from!(MetadataError => Error::Metadata);
-impl_from!(scale_decode::Error => Error::Decode);
-impl_from!(scale_decode::visitor::DecodeError => Error::Decode);
-impl_from!(scale_encode::Error => Error::Encode);
-impl_from!(StorageAddressError => Error::StorageAddress);
-impl_from!(codec::Error => Error::Codec);
-
/// Block error
-#[derive(Debug)]
+#[derive(Debug, DeriveError)]
pub enum BlockError {
/// Leftover bytes found after decoding the extrinsic.
+ #[error("After decoding the extrinsic at index {extrinsic_index}, {num_leftover_bytes} bytes were left, suggesting that decoding may have failed")]
LeftoverBytes {
/// Index of the extrinsic that failed to decode.
extrinsic_index: usize,
@@ -66,6 +47,7 @@ pub enum BlockError {
num_leftover_bytes: usize,
},
/// Something went wrong decoding the extrinsic.
+ #[error("Failed to decode extrinsic at index {extrinsic_index}: {error}")]
ExtrinsicDecodeError {
/// Index of the extrinsic that failed to decode.
extrinsic_index: usize,
@@ -73,121 +55,74 @@ pub enum BlockError {
error: ExtrinsicDecodeError,
},
}
-impl Display for BlockError {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- match self {
- BlockError::LeftoverBytes {
- extrinsic_index,
- num_leftover_bytes,
- } => {
- write!(
- f,
- "After decoding the extrinsic at index {extrinsic_index}, {num_leftover_bytes} bytes were left, suggesting that decoding may have failed"
- )
- }
- BlockError::ExtrinsicDecodeError {
- extrinsic_index,
- error,
- } => {
- write!(
- f,
- "Failed to decode extrinsic at index {extrinsic_index}: {error}"
- )
- }
- }
- }
-}
/// An alias for [`frame_decode::extrinsics::ExtrinsicDecodeError`].
///
pub type ExtrinsicDecodeError = frame_decode::extrinsics::ExtrinsicDecodeError;
/// Something went wrong trying to access details in the metadata.
-#[derive(Clone, Debug, PartialEq)]
+#[derive(Clone, Debug, PartialEq, DeriveError)]
#[non_exhaustive]
pub enum MetadataError {
/// The DispatchError type isn't available in the metadata
+ #[error("The DispatchError type isn't available")]
DispatchErrorNotFound,
/// Type not found in metadata.
+ #[error("Type with ID {0} not found")]
TypeNotFound(u32),
/// Pallet not found (index).
+ #[error("Pallet with index {0} not found")]
PalletIndexNotFound(u8),
/// Pallet not found (name).
+ #[error("Pallet with name {0} not found")]
PalletNameNotFound(String),
/// Variant not found.
+ #[error("Variant with index {0} not found")]
VariantIndexNotFound(u8),
/// Constant not found.
+ #[error("Constant with name {0} not found")]
ConstantNameNotFound(String),
/// Call not found.
+ #[error("Call with name {0} not found")]
CallNameNotFound(String),
/// Runtime trait not found.
+ #[error("Runtime trait with name {0} not found")]
RuntimeTraitNotFound(String),
/// Runtime method not found.
+ #[error("Runtime method with name {0} not found")]
RuntimeMethodNotFound(String),
/// Call type not found in metadata.
+ #[error("Call type not found in pallet with index {0}")]
CallTypeNotFoundInPallet(u8),
/// Event type not found in metadata.
+ #[error("Event type not found in pallet with index {0}")]
EventTypeNotFoundInPallet(u8),
/// Storage details not found in metadata.
+ #[error("Storage details not found in pallet with name {0}")]
StorageNotFoundInPallet(String),
/// Storage entry not found.
+ #[error("Storage entry {0} not found")]
StorageEntryNotFound(String),
/// The generated interface used is not compatible with the node.
+ #[error("The generated code is not compatible with the node")]
IncompatibleCodegen,
/// Custom value not found.
+ #[error("Custom value with name {0} not found")]
CustomValueNameNotFound(String),
}
-impl Display for MetadataError {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- match self {
- MetadataError::DispatchErrorNotFound => {
- write!(f, "The DispatchError type isn't available")
- }
- MetadataError::TypeNotFound(e) => write!(f, "Type with ID {e} not found"),
- MetadataError::PalletIndexNotFound(e) => write!(f, "Pallet with index {e} not found"),
- MetadataError::PalletNameNotFound(e) => write!(f, "Pallet with name {e} not found"),
- MetadataError::VariantIndexNotFound(e) => write!(f, "Variant with index {e} not found"),
- MetadataError::ConstantNameNotFound(e) => write!(f, "Constant with name {e} not found"),
- MetadataError::CallNameNotFound(e) => write!(f, "Call with name {e} not found"),
- MetadataError::RuntimeTraitNotFound(e) => {
- write!(f, "Runtime trait with name {e} not found")
- }
- MetadataError::RuntimeMethodNotFound(e) => {
- write!(f, "Runtime method with name {e} not found")
- }
- MetadataError::CallTypeNotFoundInPallet(e) => {
- write!(f, "Call type not found in pallet with index {e}")
- }
- MetadataError::EventTypeNotFoundInPallet(e) => {
- write!(f, "Event type not found in pallet with index {e}")
- }
- MetadataError::StorageNotFoundInPallet(e) => {
- write!(f, "Storage details not found in pallet with name {e}")
- }
- MetadataError::StorageEntryNotFound(e) => write!(f, "Storage entry {e} not found"),
- MetadataError::IncompatibleCodegen => {
- write!(f, "The generated code is not compatible with the node")
- }
- MetadataError::CustomValueNameNotFound(e) => {
- write!(f, "Custom value with name {e} not found")
- }
- }
- }
-}
-
-#[cfg(feature = "std")]
-impl std::error::Error for MetadataError {}
/// Something went wrong trying to encode or decode a storage address.
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, DeriveError)]
#[non_exhaustive]
pub enum StorageAddressError {
/// Storage lookup does not have the expected number of keys.
+ #[error("Storage lookup requires {expected} keys but more keys have been provided.")]
TooManyKeys {
/// The number of keys provided in the storage address.
expected: usize,
},
/// This storage entry in the metadata does not have the correct number of hashers to fields.
+ #[error("Storage entry in metadata does not have the correct number of hashers to fields")]
WrongNumberOfHashers {
/// The number of hashers in the metadata for this storage entry.
hashers: usize,
@@ -195,12 +130,16 @@ pub enum StorageAddressError {
fields: usize,
},
/// We weren't given enough bytes to decode the storage address/key.
+ #[error("Not enough remaining bytes to decode the storage address/key")]
NotEnoughBytes,
/// We have leftover bytes after decoding the storage address.
+ #[error("We have leftover bytes after decoding the storage address")]
TooManyBytes,
/// The bytes of a storage address are not the expected address for decoding the storage keys of the address.
+ #[error("Storage address bytes are not the expected format. Addresses need to be at least 16 bytes (pallet ++ entry) and follow a structure given by the hashers defined in the metadata")]
UnexpectedAddressBytes,
/// An invalid hasher was used to reconstruct a value from a chunk of bytes that is part of a storage address. Hashers where the hash does not contain the original value are invalid for this purpose.
+ #[error("An invalid hasher was used to reconstruct a value with type ID {ty_id} from a hash formed by a {hasher:?} hasher. This is only possible for concat-style hashers or the identity hasher")]
HasherCannotReconstructKey {
/// Type id of the key's type.
ty_id: u32,
@@ -209,47 +148,14 @@ pub enum StorageAddressError {
},
}
-impl Display for StorageAddressError {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- match self {
- StorageAddressError::TooManyKeys { expected } => write!(
- f,
- "Storage lookup requires {expected} keys but more keys have been provided."
- ),
- StorageAddressError::WrongNumberOfHashers { .. } => write!(
- f,
- "Storage entry in metadata does not have the correct number of hashers to fields"
- ),
- StorageAddressError::NotEnoughBytes => write!(
- f,
- "Not enough remaining bytes to decode the storage address/key"
- ),
- StorageAddressError::TooManyBytes => write!(
- f,
- "We have leftover bytes after decoding the storage address"
- ),
- StorageAddressError::UnexpectedAddressBytes => write!(
- f,
- "Storage address bytes are not the expected format. Addresses need to be at least 16 bytes (pallet ++ entry) and follow a structure given by the hashers defined in the metadata"
- ),
- StorageAddressError::HasherCannotReconstructKey { ty_id, hasher } => write!(
- f,
- "An invalid hasher was used to reconstruct a value with type ID {ty_id} from a hash formed by a {hasher:?} hasher. This is only possible for concat-style hashers or the identity hasher"
- ),
- }
- }
-}
-
-#[cfg(feature = "std")]
-impl std::error::Error for StorageAddressError {}
-
/// An error that can be emitted when trying to construct an instance of [`crate::config::ExtrinsicParams`],
/// encode data from the instance, or match on signed extensions.
-#[derive(Debug)]
+#[derive(Debug, DeriveError)]
#[non_exhaustive]
pub enum ExtrinsicParamsError {
/// Cannot find a type id in the metadata. The context provides some additional
/// information about the source of the error (eg the signed extension name).
+ #[error("Cannot find type id '{type_id} in the metadata (context: {context})")]
MissingTypeId {
/// Type ID.
type_id: u32,
@@ -257,29 +163,13 @@ pub enum ExtrinsicParamsError {
context: &'static str,
},
/// A signed extension in use on some chain was not provided.
+ #[error("The chain expects a signed extension with the name {0}, but we did not provide one")]
UnknownSignedExtension(String),
/// Some custom error.
+ #[error("Error constructing extrinsic parameters: {0}")]
Custom(Box),
}
-impl Display for ExtrinsicParamsError {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- match self {
- ExtrinsicParamsError::MissingTypeId { type_id, context } => write!(
- f,
- "Cannot find type id '{type_id} in the metadata (context: {context})"
- ),
- ExtrinsicParamsError::UnknownSignedExtension(e) => write!(
- f,
- "The chain expects a signed extension with the name {e}, but we did not provide one"
- ),
- ExtrinsicParamsError::Custom(e) => {
- write!(f, "Error constructing extrinsic parameters: {e}")
- }
- }
- }
-}
-
/// Anything implementing this trait can be used in [`ExtrinsicParamsError::Custom`].
#[cfg(feature = "std")]
pub trait CustomError: std::error::Error + Send + Sync + 'static {}
@@ -292,9 +182,6 @@ pub trait CustomError: core::fmt::Debug + core::fmt::Display + Send + Sync + 'st
#[cfg(not(feature = "std"))]
impl CustomError for T {}
-#[cfg(feature = "std")]
-impl std::error::Error for ExtrinsicParamsError {}
-
impl From for ExtrinsicParamsError {
fn from(value: core::convert::Infallible) -> Self {
match value {}
diff --git a/core/src/events.rs b/core/src/events.rs
index 98103e3615..900b5efa20 100644
--- a/core/src/events.rs
+++ b/core/src/events.rs
@@ -376,7 +376,8 @@ impl EventDetails {
.map(|f| scale_decode::Field::new(f.ty.id, f.name.as_deref()));
let decoded =
- scale_value::scale::decode_as_fields(bytes, &mut fields, self.metadata.types())?;
+ scale_value::scale::decode_as_fields(bytes, &mut fields, self.metadata.types())
+ .map_err(Into::::into)?;
Ok(decoded)
}
diff --git a/core/src/macros.rs b/core/src/macros.rs
index 7b0117c959..8e25742c88 100644
--- a/core/src/macros.rs
+++ b/core/src/macros.rs
@@ -18,14 +18,4 @@ macro_rules! cfg_substrate_compat {
};
}
-macro_rules! impl_from {
- ($module_path:path => $delegate_ty:ident :: $variant:ident) => {
- impl From<$module_path> for $delegate_ty {
- fn from(val: $module_path) -> Self {
- $delegate_ty::$variant(val.into())
- }
- }
- };
-}
-
pub(crate) use {cfg_feature, cfg_substrate_compat};
diff --git a/core/src/storage/storage_key.rs b/core/src/storage/storage_key.rs
index 6ecd20180b..c1dbea4361 100644
--- a/core/src/storage/storage_key.rs
+++ b/core/src/storage/storage_key.rs
@@ -264,7 +264,9 @@ impl StorageKey for Vec {
match consume_hash_returning_key_bytes(bytes, hasher, ty_id, types)? {
Some(value_bytes) => {
let value =
- scale_value::scale::decode_as_type(&mut &*value_bytes, ty_id, types)?;
+ scale_value::scale::decode_as_type(&mut &*value_bytes, ty_id, types)
+ .map_err(Into::::into)?;
+
result.push(value.remove_context());
}
None => {
diff --git a/core/src/utils/account_id.rs b/core/src/utils/account_id.rs
index 714ccf2705..40fd68c42c 100644
--- a/core/src/utils/account_id.rs
+++ b/core/src/utils/account_id.rs
@@ -6,14 +6,13 @@
//! This doesn't contain much functionality itself, but is easy to convert to/from an `sp_core::AccountId32`
//! for instance, to gain functionality without forcing a dependency on Substrate crates here.
-use core::fmt::Display;
-
use alloc::format;
use alloc::string::String;
use alloc::vec;
use alloc::vec::Vec;
use codec::{Decode, Encode};
use serde::{Deserialize, Serialize};
+use thiserror::Error as DeriveError;
/// A 32-byte cryptographic identifier. This is a simplified version of Substrate's
/// `sp_core::crypto::AccountId32`. To obtain more functionality, convert this into
@@ -106,29 +105,19 @@ impl AccountId32 {
}
/// An error obtained from trying to interpret an SS58 encoded string into an AccountId32
-#[derive(Clone, Copy, Eq, PartialEq, Debug)]
+#[derive(Clone, Copy, Eq, PartialEq, Debug, DeriveError)]
#[allow(missing_docs)]
pub enum FromSs58Error {
+ #[error("Base 58 requirement is violated")]
BadBase58,
+ #[error("Length is bad")]
BadLength,
+ #[error("Invalid checksum")]
InvalidChecksum,
+ #[error("Invalid SS58 prefix byte.")]
InvalidPrefix,
}
-impl Display for FromSs58Error {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- match self {
- FromSs58Error::BadBase58 => write!(f, "Base 58 requirement is violated"),
- FromSs58Error::BadLength => write!(f, "Length is bad"),
- FromSs58Error::InvalidChecksum => write!(f, "Invalid checksum"),
- FromSs58Error::InvalidPrefix => write!(f, "Invalid SS58 prefix byte."),
- }
- }
-}
-
-#[cfg(feature = "std")]
-impl std::error::Error for FromSs58Error {}
-
// We do this just to get a checksum to help verify the validity of the address in to_ss58check
fn ss58hash(data: &[u8]) -> Vec {
use blake2::{Blake2b512, Digest};
diff --git a/core/src/utils/account_id20.rs b/core/src/utils/account_id20.rs
index 48f9306349..4d32796fa9 100644
--- a/core/src/utils/account_id20.rs
+++ b/core/src/utils/account_id20.rs
@@ -4,13 +4,12 @@
//! `AccountId20` is a representation of Ethereum address derived from hashing the public key.
-use core::fmt::Display;
-
use alloc::format;
use alloc::string::String;
use codec::{Decode, Encode};
use keccak_hash::keccak;
use serde::{Deserialize, Serialize};
+use thiserror::Error as DeriveError;
#[derive(
Copy,
@@ -72,27 +71,17 @@ impl AccountId20 {
}
/// An error obtained from trying to interpret a hex encoded string into an AccountId20
-#[derive(Clone, Copy, Eq, PartialEq, Debug)]
+#[derive(Clone, Copy, Eq, PartialEq, Debug, DeriveError)]
#[allow(missing_docs)]
pub enum FromChecksumError {
+ #[error("Length is bad")]
BadLength,
+ #[error("Invalid checksum")]
InvalidChecksum,
+ #[error("Invalid checksum prefix byte.")]
InvalidPrefix,
}
-impl Display for FromChecksumError {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- match self {
- FromChecksumError::BadLength => write!(f, "Length is bad"),
- FromChecksumError::InvalidChecksum => write!(f, "Invalid checksum"),
- FromChecksumError::InvalidPrefix => write!(f, "Invalid checksum prefix byte."),
- }
- }
-}
-
-#[cfg(feature = "std")]
-impl std::error::Error for FromChecksumError {}
-
impl Serialize for AccountId20 {
fn serialize(&self, serializer: S) -> Result
where
diff --git a/metadata/Cargo.toml b/metadata/Cargo.toml
index fb34cfa2fd..73406a43da 100644
--- a/metadata/Cargo.toml
+++ b/metadata/Cargo.toml
@@ -24,6 +24,7 @@ frame-metadata = { workspace = true, default-features = false, features = ["curr
codec = { package = "parity-scale-codec", workspace = true, default-features = false, features = ["derive"] }
polkadot-sdk = { workspace = true, features = ["sp-crypto-hashing"] }
hashbrown = { workspace = true }
+thiserror = { workspace = true, default-features = false }
[dev-dependencies]
bitvec = { workspace = true, features = ["alloc"] }
diff --git a/metadata/src/from_into/mod.rs b/metadata/src/from_into/mod.rs
index 0c34afe375..bbb5d8c0b6 100644
--- a/metadata/src/from_into/mod.rs
+++ b/metadata/src/from_into/mod.rs
@@ -2,56 +2,33 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
-use core::fmt::Display;
-
use alloc::string::String;
-
+use thiserror::Error as DeriveError;
mod v14;
mod v15;
/// An error emitted if something goes wrong converting [`frame_metadata`]
/// types into [`crate::Metadata`].
-#[derive(Debug, PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq, DeriveError)]
#[non_exhaustive]
pub enum TryFromError {
/// Type missing from type registry
+ #[error("Type id {0} is expected but not found in the type registry")]
TypeNotFound(u32),
/// Type was not a variant/enum type
+ #[error("Type {0} was not a variant/enum type, but is expected to be one")]
VariantExpected(u32),
/// An unsupported metadata version was provided.
+ #[error("Cannot convert v{0} metadata into Metadata type")]
UnsupportedMetadataVersion(u32),
/// Type name missing from type registry
+ #[error("Type name {0} is expected but not found in the type registry")]
TypeNameNotFound(String),
/// Invalid type path.
+ #[error("Type has an invalid path {0}")]
InvalidTypePath(String),
}
-impl Display for TryFromError {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- match self {
- TryFromError::TypeNotFound(e) => write!(
- f,
- "Type id {e} is expected but not found in the type registry"
- ),
- TryFromError::VariantExpected(e) => write!(
- f,
- "Type {e} was not a variant/enum type, but is expected to be one"
- ),
- TryFromError::UnsupportedMetadataVersion(e) => {
- write!(f, "Cannot convert v{e} metadata into Metadata type")
- }
- TryFromError::TypeNameNotFound(e) => write!(
- f,
- "Type name {e} is expected but not found in the type registry"
- ),
- TryFromError::InvalidTypePath(e) => write!(f, "Type has an invalid path {e}"),
- }
- }
-}
-
-#[cfg(feature = "std")]
-impl std::error::Error for TryFromError {}
-
impl From for frame_metadata::RuntimeMetadataPrefixed {
fn from(value: crate::Metadata) -> Self {
let m: frame_metadata::v15::RuntimeMetadataV15 = value.into();
diff --git a/signer/Cargo.toml b/signer/Cargo.toml
index fc2f5d10f6..acc6e66890 100644
--- a/signer/Cargo.toml
+++ b/signer/Cargo.toml
@@ -72,6 +72,7 @@ secp256k1 = { workspace = true, optional = true, features = [
"recovery",
] }
keccak-hash = { workspace = true, optional = true }
+thiserror = { workspace = true, default-features = false }
# These are used if the polkadot-js-compat feature is enabled
serde = { workspace = true, optional = true }
diff --git a/signer/src/ecdsa.rs b/signer/src/ecdsa.rs
index 69bda852e7..6c9367e2eb 100644
--- a/signer/src/ecdsa.rs
+++ b/signer/src/ecdsa.rs
@@ -7,11 +7,13 @@ use codec::Encode;
use polkadot_sdk::sp_crypto_hashing;
use crate::crypto::{seed_from_entropy, DeriveJunction, SecretUri};
-use core::{fmt::Display, str::FromStr};
+use core::str::FromStr;
use hex::FromHex;
use secp256k1::{ecdsa::RecoverableSignature, Message, Secp256k1, SecretKey};
use secrecy::ExposeSecret;
+use thiserror::Error as DeriveError;
+
const SECRET_KEY_LENGTH: usize = 32;
/// Seed bytes used to generate a key pair.
@@ -222,34 +224,22 @@ pub(crate) mod internal {
}
/// An error handed back if creating a keypair fails.
-#[derive(Debug, PartialEq)]
+#[derive(Debug, PartialEq, DeriveError)]
pub enum Error {
/// Invalid seed.
+ #[error("Invalid seed (was it the wrong length?)")]
InvalidSeed,
/// Invalid seed.
+ #[error("Invalid seed for ECDSA, contained soft junction")]
SoftJunction,
/// Invalid phrase.
- Phrase(bip39::Error),
+ #[error("Cannot parse phrase: {0}")]
+ Phrase(#[from] bip39::Error),
/// Invalid hex.
- Hex(hex::FromHexError),
-}
-impl Display for Error {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- match self {
- Error::InvalidSeed => write!(f, "Invalid seed (was it the wrong length?)"),
- Error::SoftJunction => write!(f, "Invalid seed for ECDSA, contained soft junction"),
- Error::Phrase(e) => write!(f, "Cannot parse phrase: {e}"),
- Error::Hex(e) => write!(f, "Cannot parse hex string: {e}"),
- }
- }
+ #[error("Cannot parse hex string: {0}")]
+ Hex(#[from] hex::FromHexError),
}
-impl_from!(bip39::Error => Error::Phrase);
-impl_from!(hex::FromHexError => Error::Hex);
-
-#[cfg(feature = "std")]
-impl std::error::Error for Error {}
-
/// Dev accounts, helpful for testing but not to be used in production,
/// since the secret keys are known.
pub mod dev {
diff --git a/signer/src/eth.rs b/signer/src/eth.rs
index bc92d51029..a8933b82c1 100644
--- a/signer/src/eth.rs
+++ b/signer/src/eth.rs
@@ -6,11 +6,13 @@
use crate::ecdsa;
use alloc::format;
-use core::fmt::{Display, Formatter};
+use core::fmt::Formatter;
use core::str::FromStr;
use keccak_hash::keccak;
use secp256k1::Message;
+use thiserror::Error as DeriveError;
+
const SECRET_KEY_LENGTH: usize = 32;
/// Bytes representing a private key.
@@ -201,29 +203,16 @@ pub fn verify>(sig: &Signature, message: M, pubkey: &PublicKey) -
}
/// An error handed back if creating a keypair fails.
-#[derive(Debug, PartialEq)]
+#[derive(Debug, PartialEq, DeriveError)]
pub enum Error {
/// Invalid seed.
+ #[error("Invalid seed (was it the wrong length?)")]
InvalidSeed,
/// Invalid derivation path.
+ #[error("Could not derive from path; some values in the path may have been >= 2^31?")]
DeriveFromPath,
}
-impl Display for Error {
- fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
- match self {
- Error::InvalidSeed => write!(f, "Invalid seed (was it the wrong length?)"),
- Error::DeriveFromPath => write!(
- f,
- "Could not derive from path; some values in the path may have been >= 2^31?"
- ),
- }
- }
-}
-
-#[cfg(feature = "std")]
-impl std::error::Error for Error {}
-
/// Dev accounts, helpful for testing but not to be used in production,
/// since the secret keys are known.
pub mod dev {
diff --git a/signer/src/polkadot_js_compat.rs b/signer/src/polkadot_js_compat.rs
index b90f87efa6..5aa155fe59 100644
--- a/signer/src/polkadot_js_compat.rs
+++ b/signer/src/polkadot_js_compat.rs
@@ -5,7 +5,6 @@
//! A Polkadot-JS account loader.
use base64::Engine;
-use core::fmt::Display;
use crypto_secretbox::{
aead::{Aead, KeyInit},
Key, Nonce, XSalsa20Poly1305,
@@ -13,6 +12,8 @@ use crypto_secretbox::{
use serde::Deserialize;
use subxt_core::utils::AccountId32;
+use thiserror::Error as DeriveError;
+
use crate::sr25519;
/// Given a JSON keypair as exported from Polkadot-JS, this returns an [`sr25519::Keypair`]
@@ -22,15 +23,19 @@ pub fn decrypt_json(json: &str, password: &str) -> Result Error::Json);
-impl_from!(base64::DecodeError => Error::Base64);
-impl_from!(crypto_secretbox::Error => Error::Secretbox);
-impl_from!(sr25519::Error => Error::Sr25519);
-
-impl Display for Error {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- match self {
- Error::Json(e) => write!(f, "Invalid JSON: {e}"),
- Error::UnsupportedEncoding => write!(f, "Unsupported encoding."),
- Error::Base64(e) => write!(f, "Base64 decoding error: {e}"),
- Error::UnsupportedScryptParameters { n, p, r } => {
- write!(f, "Unsupported Scrypt parameters: N: {n}, p: {p}, r: {r}")
- }
- Error::Secretbox(e) => write!(f, "Decryption error: {e}"),
- Error::Sr25519(e) => write!(f, "{e}"),
- Error::InvalidKeys => write!(f, "The decrypted keys are not valid."),
- }
- }
-}
-
-#[cfg(feature = "std")]
-impl std::error::Error for Error {}
-
#[derive(Deserialize)]
struct EncryptionMetadata {
/// Descriptor for the content
diff --git a/signer/src/sr25519.rs b/signer/src/sr25519.rs
index c566753f84..213b8e1082 100644
--- a/signer/src/sr25519.rs
+++ b/signer/src/sr25519.rs
@@ -4,7 +4,7 @@
//! An sr25519 keypair implementation.
-use core::{fmt::Display, str::FromStr};
+use core::str::FromStr;
use crate::crypto::{seed_from_entropy, DeriveJunction, SecretUri};
@@ -15,6 +15,8 @@ use schnorrkel::{
};
use secrecy::ExposeSecret;
+use thiserror::Error as DeriveError;
+
const SECRET_KEY_LENGTH: usize = schnorrkel::keys::MINI_SECRET_KEY_LENGTH;
const SIGNING_CTX: &[u8] = b"substrate";
@@ -203,36 +205,28 @@ pub fn verify>(sig: &Signature, message: M, pubkey: &PublicKey) -
}
/// An error handed back if creating a keypair fails.
-#[derive(Debug)]
+#[derive(Debug, DeriveError)]
pub enum Error {
/// Invalid seed.
+ #[error("Invalid seed (was it the wrong length?)")]
InvalidSeed,
/// Invalid phrase.
- Phrase(bip39::Error),
+ #[error("Cannot parse phrase: {0}")]
+ Phrase(#[from] bip39::Error),
/// Invalid hex.
- Hex(hex::FromHexError),
+ #[error("Cannot parse hex string: {0}")]
+ Hex(#[from] hex::FromHexError),
/// Signature error.
+ #[error("Signature error: {0}")]
Signature(schnorrkel::SignatureError),
}
-impl_from!(bip39::Error => Error::Phrase);
-impl_from!(hex::FromHexError => Error::Hex);
-impl_from!(schnorrkel::SignatureError => Error::Signature);
-
-impl Display for Error {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- match self {
- Error::InvalidSeed => write!(f, "Invalid seed (was it the wrong length?)"),
- Error::Phrase(e) => write!(f, "Cannot parse phrase: {e}"),
- Error::Hex(e) => write!(f, "Cannot parse hex string: {e}"),
- Error::Signature(e) => write!(f, "Signature error: {e}"),
- }
+impl From for Error {
+ fn from(value: schnorrkel::SignatureError) -> Self {
+ Error::Signature(value)
}
}
-#[cfg(feature = "std")]
-impl std::error::Error for Error {}
-
/// Dev accounts, helpful for testing but not to be used in production,
/// since the secret keys are known.
pub mod dev {
From 75e637163e945f14cfb5cdf96d26dbcbbc6a80a4 Mon Sep 17 00:00:00 2001
From: Pavlo Khrystenko
Date: Wed, 6 Nov 2024 13:24:26 +0100
Subject: [PATCH 2/5] missing bits
---
signer/src/crypto/secret_uri.rs | 18 ++++--------------
signer/src/eth.rs | 1 -
signer/src/utils.rs | 10 ----------
3 files changed, 4 insertions(+), 25 deletions(-)
diff --git a/signer/src/crypto/secret_uri.rs b/signer/src/crypto/secret_uri.rs
index 0d93db202e..b30e61d881 100644
--- a/signer/src/crypto/secret_uri.rs
+++ b/signer/src/crypto/secret_uri.rs
@@ -2,13 +2,13 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
-use core::fmt::Display;
-
use super::DeriveJunction;
use alloc::{string::ToString, vec::Vec};
use regex::Regex;
use secrecy::SecretString;
+use thiserror::Error as DeriveError;
+
// This code is taken from sp_core::crypto::DeriveJunction. The logic should be identical,
// though the code is tweaked a touch!
@@ -116,23 +116,13 @@ impl core::str::FromStr for SecretUri {
}
/// This is returned if `FromStr` cannot parse a string into a `SecretUri`.
-#[derive(Debug, Copy, Clone, PartialEq)]
+#[derive(Debug, Copy, Clone, PartialEq, DeriveError)]
pub enum SecretUriError {
/// Parsing the secret URI from a string failed; wrong format.
+ #[error("Invalid secret phrase format")]
InvalidFormat,
}
-impl Display for SecretUriError {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- match self {
- SecretUriError::InvalidFormat => write!(f, "Invalid secret phrase format"),
- }
- }
-}
-
-#[cfg(feature = "std")]
-impl std::error::Error for SecretUriError {}
-
once_static_cloned! {
/// Interpret a phrase like:
///
diff --git a/signer/src/eth.rs b/signer/src/eth.rs
index a8933b82c1..8a4a91158b 100644
--- a/signer/src/eth.rs
+++ b/signer/src/eth.rs
@@ -6,7 +6,6 @@
use crate::ecdsa;
use alloc::format;
-use core::fmt::Formatter;
use core::str::FromStr;
use keccak_hash::keccak;
use secp256k1::Message;
diff --git a/signer/src/utils.rs b/signer/src/utils.rs
index 72b6e14fa7..64358cee42 100644
--- a/signer/src/utils.rs
+++ b/signer/src/utils.rs
@@ -35,13 +35,3 @@ macro_rules! once_static_cloned {
)+
};
}
-
-macro_rules! impl_from {
- ($module_path:path => $delegate_ty:ident :: $variant:ident) => {
- impl From<$module_path> for $delegate_ty {
- fn from(val: $module_path) -> Self {
- $delegate_ty::$variant(val.into())
- }
- }
- };
-}
From 14a506280d5a8d6bc4c05790f0c0a96286bd3c4e Mon Sep 17 00:00:00 2001
From: Pavlo Khrystenko
Date: Wed, 6 Nov 2024 13:46:32 +0100
Subject: [PATCH 3/5] review comment
---
core/Cargo.toml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 0aba388510..d78d8dc270 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -49,6 +49,8 @@ hex = { workspace = true, default-features = false, features = ["alloc"] }
serde = { workspace = true, default-features = false, features = ["derive"] }
serde_json = { workspace = true, default-features = false, features = ["raw_value", "alloc"] }
hashbrown = { workspace = true }
+thiserror = { workspace = true, default-features = false }
+
# For ss58 encoding AccountId32 to serialize them properly:
base58 = { workspace = true }
@@ -65,8 +67,6 @@ tracing = { workspace = true, default-features = false }
# AccountId20
keccak-hash = { workspace = true}
-# Error handling
-thiserror = { workspace = true, default-features = false }
[dev-dependencies]
assert_matches = { workspace = true }
From 28a2a78059f51a8579c96a4713fbab8464908115 Mon Sep 17 00:00:00 2001
From: Pavlo Khrystenko <45178695+pkhry@users.noreply.github.com>
Date: Wed, 6 Nov 2024 13:52:56 +0100
Subject: [PATCH 4/5] Apply suggestions from code review
Co-authored-by: Niklas Adolfsson
---
core/src/error.rs | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/core/src/error.rs b/core/src/error.rs
index efaf448139..94acf9a107 100644
--- a/core/src/error.rs
+++ b/core/src/error.rs
@@ -13,13 +13,13 @@ use thiserror::Error as DeriveError;
#[derive(Debug, DeriveError)]
pub enum Error {
/// Codec error.
- #[error("Scale codec error: {0}")]
+ #[error(transparent)]
Codec(#[from] codec::Error),
/// Metadata error.
- #[error("Metadata Error: {0}")]
+ #[error(transparent)]
Metadata(#[from] MetadataError),
/// Storage address error.
- #[error("Storage Error: {0}")]
+ #[error(transparent)]
StorageAddress(#[from] StorageAddressError),
/// Error decoding to a [`crate::dynamic::Value`].
#[error("Error decoding into dynamic value: {0}")]
@@ -28,7 +28,7 @@ pub enum Error {
#[error("Error encoding from dynamic value: {0}")]
Encode(#[from] scale_encode::Error),
/// Error constructing the appropriate extrinsic params.
- #[error("Extrinsic params error: {0}")]
+ #[error(transparent)]
ExtrinsicParams(#[from] ExtrinsicParamsError),
/// Block body error.
#[error("Error working with block_body: {0}")]
From 8ff3479a6a3b4dacaff4a936b47d80c1a92f81fa Mon Sep 17 00:00:00 2001
From: James Wilson
Date: Wed, 6 Nov 2024 15:16:45 +0000
Subject: [PATCH 5/5] From to remove Into::intos
---
core/src/blocks/extrinsic_signed_extensions.rs | 3 +--
core/src/blocks/extrinsics.rs | 3 +--
core/src/error.rs | 6 ++++++
core/src/events.rs | 3 +--
core/src/storage/storage_key.rs | 3 +--
5 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/core/src/blocks/extrinsic_signed_extensions.rs b/core/src/blocks/extrinsic_signed_extensions.rs
index 8be6c3308f..4731cba6b0 100644
--- a/core/src/blocks/extrinsic_signed_extensions.rs
+++ b/core/src/blocks/extrinsic_signed_extensions.rs
@@ -120,8 +120,7 @@ impl<'a, T: Config> ExtrinsicSignedExtension<'a, T> {
&mut &self.bytes[..],
self.ty_id,
self.metadata.types(),
- )
- .map_err(Into::::into)?;
+ )?;
Ok(value)
}
diff --git a/core/src/blocks/extrinsics.rs b/core/src/blocks/extrinsics.rs
index 52d945de95..ac58ab87f4 100644
--- a/core/src/blocks/extrinsics.rs
+++ b/core/src/blocks/extrinsics.rs
@@ -287,8 +287,7 @@ where
.iter()
.map(|f| scale_decode::Field::new(f.ty.id, f.name.as_deref()));
let decoded =
- scale_value::scale::decode_as_fields(bytes, &mut fields, self.metadata.types())
- .map_err(Into::::into)?;
+ scale_value::scale::decode_as_fields(bytes, &mut fields, self.metadata.types())?;
Ok(decoded)
}
diff --git a/core/src/error.rs b/core/src/error.rs
index 94acf9a107..795acecd20 100644
--- a/core/src/error.rs
+++ b/core/src/error.rs
@@ -35,6 +35,12 @@ pub enum Error {
Block(#[from] BlockError),
}
+impl From for Error {
+ fn from(err: scale_decode::visitor::DecodeError) -> Error {
+ Error::Decode(err.into())
+ }
+}
+
/// Block error
#[derive(Debug, DeriveError)]
pub enum BlockError {
diff --git a/core/src/events.rs b/core/src/events.rs
index 900b5efa20..98103e3615 100644
--- a/core/src/events.rs
+++ b/core/src/events.rs
@@ -376,8 +376,7 @@ impl EventDetails {
.map(|f| scale_decode::Field::new(f.ty.id, f.name.as_deref()));
let decoded =
- scale_value::scale::decode_as_fields(bytes, &mut fields, self.metadata.types())
- .map_err(Into::::into)?;
+ scale_value::scale::decode_as_fields(bytes, &mut fields, self.metadata.types())?;
Ok(decoded)
}
diff --git a/core/src/storage/storage_key.rs b/core/src/storage/storage_key.rs
index c1dbea4361..1fb128b08a 100644
--- a/core/src/storage/storage_key.rs
+++ b/core/src/storage/storage_key.rs
@@ -264,8 +264,7 @@ impl StorageKey for Vec {
match consume_hash_returning_key_bytes(bytes, hasher, ty_id, types)? {
Some(value_bytes) => {
let value =
- scale_value::scale::decode_as_type(&mut &*value_bytes, ty_id, types)
- .map_err(Into::::into)?;
+ scale_value::scale::decode_as_type(&mut &*value_bytes, ty_id, types)?;
result.push(value.remove_context());
}