From caf6f7b7d96f038fb0741c436c652611a3bf90f8 Mon Sep 17 00:00:00 2001 From: Igor Zhirkov Date: Mon, 3 Feb 2025 23:25:07 +0100 Subject: [PATCH] Revert "substitute error generator PoC to zksync-error" This reverts commit 0a54daedf47a613f79457ab73da632cdee14bac3. --- Cargo.lock | 169 +- Cargo.toml | 4 +- crates/zksync_error/Cargo.toml | 6 +- crates/zksync_error/src/documentation.rs | 15 +- crates/zksync_error/src/error/definitions.rs | 1701 +++++++++--------- crates/zksync_error/src/error/domains.rs | 444 +++-- crates/zksync_error/src/error/mod.rs | 50 +- crates/zksync_error/src/identifier.rs | 216 +-- crates/zksync_error/src/kind.rs | 32 +- crates/zksync_error/src/lib.rs | 373 ++-- crates/zksync_error/src/packed.rs | 18 +- crates/zksync_error/src/serialized.rs | 17 +- crates/zksync_error/src/untyped.rs | 9 +- 13 files changed, 1550 insertions(+), 1504 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9a98e484..54d5c4ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -245,7 +245,7 @@ checksum = "2b09cae092c27b6f1bde952653a22708691802e57bfef4a2973b80bea21efd3f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -333,7 +333,7 @@ dependencies = [ "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -350,7 +350,7 @@ dependencies = [ "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", "syn-solidity", "tiny-keccak 2.0.2", ] @@ -368,7 +368,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.98", + "syn 2.0.89", "syn-solidity", ] @@ -775,7 +775,7 @@ checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -786,7 +786,7 @@ checksum = "3f934833b4b7233644e5848f235df3f57ed8c80f1528a26c3dfa13d2147fa056" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -803,7 +803,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -978,7 +978,7 @@ dependencies = [ "bitflags 2.6.0", "cexpr", "clang-sys", - "itertools 0.10.5", + "itertools 0.12.1", "lazy_static", "lazycell", "log", @@ -988,7 +988,7 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex", - "syn 2.0.98", + "syn 2.0.89", "which", ] @@ -1313,7 +1313,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -1596,7 +1596,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a2785755761f3ddc1492979ce1e48d2c00d09311c39e4466429188f3dd6501" dependencies = [ "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -1702,7 +1702,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", "unicode-xid", ] @@ -1747,7 +1747,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -1861,7 +1861,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -2137,7 +2137,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -2801,7 +2801,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -2882,7 +2882,7 @@ checksum = "a0eb5a3343abf848c0984fe4604b2b105da9539376e24fc0a3b0007411ae4fd9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -2952,6 +2952,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.13.0" @@ -3112,7 +3121,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -3307,7 +3316,7 @@ dependencies = [ "proc-macro2", "quote", "regex-syntax 0.6.29", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -3372,7 +3381,7 @@ checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -3571,7 +3580,7 @@ dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -3583,7 +3592,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -3644,7 +3653,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -3825,7 +3834,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -3922,7 +3931,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -4001,7 +4010,7 @@ checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -4074,7 +4083,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" dependencies = [ "proc-macro2", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -4137,14 +4146,14 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] name = "proc-macro2" -version = "1.0.93" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -4169,7 +4178,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -4220,7 +4229,7 @@ checksum = "22505a5c94da8e3b7c2996394d1c933236c4d743e81a410bcca4e6989fc066a4" dependencies = [ "bytes", "heck", - "itertools 0.10.5", + "itertools 0.12.1", "log", "multimap", "once_cell", @@ -4229,7 +4238,7 @@ dependencies = [ "prost 0.12.6", "prost-types", "regex", - "syn 2.0.98", + "syn 2.0.89", "tempfile", ] @@ -4240,10 +4249,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" dependencies = [ "anyhow", - "itertools 0.10.5", + "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -4256,7 +4265,7 @@ dependencies = [ "itertools 0.13.0", "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -4328,9 +4337,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.38" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -4758,19 +4767,6 @@ dependencies = [ "semver 1.0.23", ] -[[package]] -name = "rustfmt-wrapper" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1adc9dfed5cc999077978cc7163b9282c5751c8d39827c4ea8c8c220ca5a440" -dependencies = [ - "serde", - "tempfile", - "thiserror 1.0.69", - "toml", - "toolchain_find", -] - [[package]] name = "rustix" version = "0.38.41" @@ -5171,7 +5167,7 @@ checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -5479,7 +5475,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -5501,9 +5497,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.98" +version = "2.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1" +checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" dependencies = [ "proc-macro2", "quote", @@ -5519,7 +5515,7 @@ dependencies = [ "paste", "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -5545,7 +5541,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -5659,7 +5655,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -5670,7 +5666,7 @@ checksum = "5c89e72a01ed4c579669add59014b9a524d609c0c88c6a585ce37485879f6ffb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", "test-case-core", ] @@ -5700,7 +5696,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -5711,7 +5707,7 @@ checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -5836,7 +5832,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -5961,19 +5957,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "toolchain_find" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc8c9a7f0a2966e1acdaf0461023d0b01471eeead645370cf4c3f5cff153f2a" -dependencies = [ - "home", - "once_cell", - "regex", - "semver 1.0.23", - "walkdir", -] - [[package]] name = "tower" version = "0.4.13" @@ -6054,7 +6037,7 @@ checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -6368,7 +6351,7 @@ checksum = "6a511871dc5de990a3b2a0e715facfbc5da848c0c0395597a1415029fb7c250a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -6433,7 +6416,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", "wasm-bindgen-shared", ] @@ -6467,7 +6450,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -6812,7 +6795,7 @@ checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", "synstructure", ] @@ -6834,7 +6817,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -6854,7 +6837,7 @@ checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", "synstructure", ] @@ -6875,7 +6858,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -6897,7 +6880,7 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] @@ -7082,22 +7065,16 @@ dependencies = [ [[package]] name = "zksync-error-codegen" version = "0.1.0" -source = "git+https://github.com/matter-labs/zksync-error?branch=main#3e3cf6bdf63f6a4c7ab4942472d84f8f5b7ba1a0" +source = "git+https://github.com/sayon/error-codegen-poc?branch=main#e6b17c21f080711e4770cb9ed3d1fa285a81cbdd" dependencies = [ "cargo_metadata", "include_dir", "maplit", - "proc-macro2", - "quote", "reqwest 0.12.9", - "rustfmt-wrapper", "serde", "serde_json", - "strum", - "strum_macros", - "syn 2.0.98", "tera", - "thiserror 1.0.69", + "toml", "vector-map", "zksync-error-description", "zksync-error-model", @@ -7106,7 +7083,7 @@ dependencies = [ [[package]] name = "zksync-error-description" version = "0.1.0" -source = "git+https://github.com/matter-labs/zksync-error?branch=main#3e3cf6bdf63f6a4c7ab4942472d84f8f5b7ba1a0" +source = "git+https://github.com/sayon/error-codegen-poc?branch=main#e6b17c21f080711e4770cb9ed3d1fa285a81cbdd" dependencies = [ "serde", "serde_json", @@ -7116,11 +7093,10 @@ dependencies = [ [[package]] name = "zksync-error-model" version = "0.1.0" -source = "git+https://github.com/matter-labs/zksync-error?branch=main#3e3cf6bdf63f6a4c7ab4942472d84f8f5b7ba1a0" +source = "git+https://github.com/sayon/error-codegen-poc?branch=main#e6b17c21f080711e4770cb9ed3d1fa285a81cbdd" dependencies = [ "serde", "serde_json", - "thiserror 1.0.69", ] [[package]] @@ -7253,7 +7229,6 @@ dependencies = [ name = "zksync_error" version = "0.1.0" dependencies = [ - "anyhow", "lazy_static", "serde", "serde_json", @@ -7377,7 +7352,7 @@ dependencies = [ "prost-reflect", "protox", "quote", - "syn 2.0.98", + "syn 2.0.89", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 692a6574..c3902020 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,8 +74,8 @@ tracing-subscriber = { version = "0.3", features = [ "local-time", ] } url = "2.5.4" -zksync-error-description = { git = "https://github.com/matter-labs/zksync-error", branch = "main" } -zksync-error-codegen = { git = "https://github.com/matter-labs/zksync-error", branch = "main", package = "zksync-error-codegen" } +zksync-error-description = { git = "https://github.com/sayon/error-codegen-poc", branch = "main" } +zksync-error-codegen = { git = "https://github.com/sayon/error-codegen-poc", branch = "main", package = "zksync-error-codegen" } strum = "0.26.3" strum_macros = "0.26.4" diff --git a/crates/zksync_error/Cargo.toml b/crates/zksync_error/Cargo.toml index f196c7f4..539a41a8 100644 --- a/crates/zksync_error/Cargo.toml +++ b/crates/zksync_error/Cargo.toml @@ -8,8 +8,8 @@ edition = "2021" [dependencies] lazy_static = "1.5.0" serde = { version = "1.0.210", features = [ "derive", "rc" ] } -serde_json = "1.0.128" +serde_json = { version = "1.0.128" } strum = "0.26.3" strum_macros = "0.26.4" -zksync-error-description = { git = "https://github.com/matter-labs/zksync-error", branch = "main"} -anyhow = "1.0" +zksync-error-description = { git = "https://github.com/sayon/error-codegen-poc", branch = "main"} + diff --git a/crates/zksync_error/src/documentation.rs b/crates/zksync_error/src/documentation.rs index ce49675c..6fe3278d 100644 --- a/crates/zksync_error/src/documentation.rs +++ b/crates/zksync_error/src/documentation.rs @@ -1,28 +1,35 @@ + //! //! AUTOGENERATED BASED ON A SET OF JSON FILES, DO NOT EDIT MANUALLY //! use lazy_static::lazy_static; use zksync_error_description::ErrorHierarchy; + lazy_static! { - pub static ref model: ErrorHierarchy = get_model(); + pub static ref model : ErrorHierarchy = get_model(); } + + fn get_model() -> ErrorHierarchy { - zksync_error_description::ErrorHierarchy::from_str(include_str!( - "../resources/error-model-dump.json" - )) + zksync_error_description::ErrorHierarchy::from_str(include_str!("../resources/error-model-dump.json")) } + #[derive(Debug)] pub enum DocumentationError { IncompleteModel(String), + } + impl std::fmt::Display for DocumentationError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_fmt(format_args!("{self:#?}")) } } impl std::error::Error for DocumentationError {} + pub trait Documented { type Documentation; fn get_documentation(&self) -> Result, DocumentationError>; } + diff --git a/crates/zksync_error/src/error/definitions.rs b/crates/zksync_error/src/error/definitions.rs index 41bdeef6..d325a984 100644 --- a/crates/zksync_error/src/error/definitions.rs +++ b/crates/zksync_error/src/error/definitions.rs @@ -1,196 +1,192 @@ + //! //! AUTOGENERATED BASED ON A SET OF JSON FILES, DO NOT EDIT MANUALLY //! + #![allow(unused)] #![allow(non_camel_case_types)] + use crate::documentation::Documented; use crate::error::CustomErrorMessage; +use crate::error::NamedError; use crate::error::ICustomError as _; use crate::error::IError as _; -use crate::error::NamedError; use strum_macros::AsRefStr; use strum_macros::EnumDiscriminants; use strum_macros::FromRepr; -#[doc = ""] -#[doc = ""] -#[doc = "Domain: Anvil"] + #[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - Eq, - EnumDiscriminants, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] +#[derive(AsRefStr, Clone, Debug, Eq, EnumDiscriminants, PartialEq, serde::Serialize, serde::Deserialize)] #[strum_discriminants(name(HaltCode))] #[strum_discriminants(vis(pub))] #[strum_discriminants(derive(AsRefStr, FromRepr))] #[non_exhaustive] pub enum Halt { - #[doc = "# Summary "] - #[doc = "Account validation failed during execution."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "This error occurs when the account validation step fails during the verification and execution of a transaction."] - ValidationFailed { - msg: String, - data: String, - } = 1u32, - #[doc = "# Summary "] - #[doc = "Paymaster validation failed."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "This error is emitted when the paymaster validation process fails during transaction execution."] - PaymasterValidationFailed { - msg: String, - data: String, - } = 2u32, - #[doc = "# Summary "] - #[doc = "Pre-paymaster preparation step failed."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "This error occurs when the system fails to prepare the paymaster before executing a transaction."] - PrePaymasterPreparationFailed { - msg: String, - data: String, - } = 3u32, - #[doc = "# Summary "] - #[doc = "Payment for the transaction failed."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "This error is emitted when the system fails to deduct the required fees for executing the transaction."] - PayForTxFailed { - msg: String, - data: String, - } = 4u32, - #[doc = "# Summary "] - #[doc = "Failed to mark factory dependencies during execution."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "This error occurs when the system cannot mark the necessary factory dependencies required for the transaction."] - FailedToMarkFactoryDependencies { - msg: String, - data: String, - } = 5u32, - #[doc = "# Summary "] - #[doc = "Charging the transaction fee failed."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "This error is emitted when the system cannot deduct the necessary fee for the transaction."] - FailedToChargeFee { - msg: String, - data: String, - } = 6u32, - #[doc = "# Summary "] - #[doc = "The sender address is not a valid account."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "This error occurs when a transaction is attempted from an address that has not been deployed as an account, meaning the `from` address is just a contract."] - FromIsNotAnAccount = 7u32, - #[doc = "# Summary "] - #[doc = "An inner transaction error occurred."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "Transaction reverted due to a contract call that failed during execution."] - InnerTxError = 8u32, - #[doc = "# Summary "] - #[doc = "An unknown error occurred."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "This error is emitted when the system encounters an unspecified reason for halting."] - Unknown { - msg: String, - data: String, - } = 9u32, - #[doc = "# Summary "] - #[doc = "The virtual machine encountered an unexpected state."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "VM entered an unforeseen state during transaction execution."] - UnexpectedVMBehavior { - problem: String, - } = 10u32, - #[doc = "# Summary "] - #[doc = "The bootloader has run out of gas."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "This error occurs when the bootloader does not have enough gas to continue executing the transaction."] - BootloaderOutOfGas = 11u32, - #[doc = "# Summary "] - #[doc = "The validation step ran out of gas."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "Validation phase of transaction execution exceeds the allocated gas limit."] - ValidationOutOfGas = 12u32, - #[doc = "# Summary "] - #[doc = "The transaction's gas limit is excessively high."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "This error occurs when the gas limit set for the transaction is too large for the server to handle."] - TooBigGasLimit = 13u32, - #[doc = "# Summary "] - #[doc = "Insufficient gas provided to initiate the transaction."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "Bootloader lacks the necessary gas to begin executing the transaction."] - NotEnoughGasProvided = 14u32, - #[doc = "# Summary "] - #[doc = "The transaction exceeded the allowed number of storage invocations."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "This error occurs when the transaction makes too many missing invocations to memory, surpassing the allowed limit."] - MissingInvocationLimitReached = 15u32, - #[doc = "# Summary "] - #[doc = "Unable to set L2 block information."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "System failed to set the necessary information for the L2 block during transaction execution."] - FailedToSetL2Block { - msg: String, - } = 16u32, - #[doc = "# Summary "] - #[doc = "Failed to add the transaction to the L2 block."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "System cannot append the transaction to the ongoing L2 block, possibly due to data inconsistencies or internal errors."] - FailedToAppendTransactionToL2Block { - msg: String, - } = 17u32, - #[doc = "# Summary "] - #[doc = "The virtual machine encountered a panic."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "VM experiences a critical failure and panic during transaction execution."] - VMPanic = 18u32, - #[doc = "# Summary "] - #[doc = "Tracer aborted the transaction execution."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "Custom tracer used during transaction execution decides to abort the process, typically due to specific conditions being met."] - TracerCustom { - msg: String, - } = 19u32, - #[doc = "# Summary "] - #[doc = "Unable to publish compressed bytecodes."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "Emitted when the system fails to publish the compressed bytecodes during transaction execution."] - FailedToPublishCompressedBytecodes = 20u32, - #[doc = "# Summary "] - #[doc = "Block timestamp assertion failed during the transaction."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "This error occurs when the transaction's execution fails to satisfy the `block.timestamp` assertion, indicating a discrepancy in the expected timestamp."] - FailedBlockTimestampAssertion = 21u32, - GenericError { - message: String, - } = 0u32, -} + /// # Short description + /// Account validation failed during execution. + /// + /// # Description + /// This error occurs when the account validation step fails during the verification and execution of a transaction. + ValidationFailed { + msg : String, + data : String, + } = 1, + /// # Short description + /// Paymaster validation failed. + /// + /// # Description + /// This error is emitted when the paymaster validation process fails during transaction execution. + PaymasterValidationFailed { + msg : String, + data : String, + } = 2, + /// # Short description + /// Pre-paymaster preparation step failed. + /// + /// # Description + /// This error occurs when the system fails to prepare the paymaster before executing a transaction. + PrePaymasterPreparationFailed { + msg : String, + data : String, + } = 3, + /// # Short description + /// Payment for the transaction failed. + /// + /// # Description + /// This error is emitted when the system fails to deduct the required fees for executing the transaction. + PayForTxFailed { + msg : String, + data : String, + } = 4, + /// # Short description + /// Failed to mark factory dependencies during execution. + /// + /// # Description + /// This error occurs when the system cannot mark the necessary factory dependencies required for the transaction. + FailedToMarkFactoryDependencies { + msg : String, + data : String, + } = 5, + /// # Short description + /// Charging the transaction fee failed. + /// + /// # Description + /// This error is emitted when the system cannot deduct the necessary fee for the transaction. + FailedToChargeFee { + msg : String, + data : String, + } = 6, + /// # Short description + /// The sender address is not a valid account. + /// + /// # Description + /// This error occurs when a transaction is attempted from an address that has not been deployed as an account, meaning the `from` address is just a contract. + FromIsNotAnAccount = 7, + /// # Short description + /// An inner transaction error occurred. + /// + /// # Description + /// Transaction reverted due to a contract call that failed during execution. + InnerTxError = 8, + /// # Short description + /// An unknown error occurred. + /// + /// # Description + /// This error is emitted when the system encounters an unspecified reason for halting. + Unknown { + msg : String, + data : String, + } = 9, + /// # Short description + /// The virtual machine encountered an unexpected state. + /// + /// # Description + /// VM entered an unforeseen state during transaction execution. + UnexpectedVMBehavior { + problem : String, + } = 10, + /// # Short description + /// The bootloader has run out of gas. + /// + /// # Description + /// This error occurs when the bootloader does not have enough gas to continue executing the transaction. + BootloaderOutOfGas = 11, + /// # Short description + /// The validation step ran out of gas. + /// + /// # Description + /// Validation phase of transaction execution exceeds the allocated gas limit. + ValidationOutOfGas = 12, + /// # Short description + /// The transaction's gas limit is excessively high. + /// + /// # Description + /// This error occurs when the gas limit set for the transaction is too large for the server to handle. + TooBigGasLimit = 13, + /// # Short description + /// Insufficient gas provided to initiate the transaction. + /// + /// # Description + /// Bootloader lacks the necessary gas to begin executing the transaction. + NotEnoughGasProvided = 14, + /// # Short description + /// The transaction exceeded the allowed number of storage invocations. + /// + /// # Description + /// This error occurs when the transaction makes too many missing invocations to memory, surpassing the allowed limit. + MissingInvocationLimitReached = 15, + /// # Short description + /// Unable to set L2 block information. + /// + /// # Description + /// System failed to set the necessary information for the L2 block during transaction execution. + FailedToSetL2Block { + msg : String, + } = 16, + /// # Short description + /// Failed to add the transaction to the L2 block. + /// + /// # Description + /// System cannot append the transaction to the ongoing L2 block, possibly due to data inconsistencies or internal errors. + FailedToAppendTransactionToL2Block { + msg : String, + } = 17, + /// # Short description + /// The virtual machine encountered a panic. + /// + /// # Description + /// VM experiences a critical failure and panic during transaction execution. + VMPanic = 18, + /// # Short description + /// Tracer aborted the transaction execution. + /// + /// # Description + /// Custom tracer used during transaction execution decides to abort the process, typically due to specific conditions being met. + TracerCustom { + msg : String, + } = 19, + /// # Short description + /// Unable to publish compressed bytecodes. + /// + /// # Description + /// Emitted when the system fails to publish the compressed bytecodes during transaction execution. + FailedToPublishCompressedBytecodes = 20, + /// # Short description + /// Block timestamp assertion failed during the transaction. + /// + /// # Description + /// This error occurs when the transaction's execution fails to satisfy the `block.timestamp` assertion, indicating a discrepancy in the expected timestamp. + FailedBlockTimestampAssertion = 21, + GenericError { + message : String, + } = 0, + +} // end of Halt + + impl std::error::Error for Halt {} + impl NamedError for Halt { fn get_error_name(&self) -> String { self.as_ref().to_owned() @@ -201,169 +197,181 @@ impl NamedError for HaltCode { self.as_ref().to_owned() } } + impl From for crate::ZksyncError { fn from(val: Halt) -> Self { val.to_unified() } } -impl std::fmt::Display for Halt { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("{self:?}")) - } -} + + impl Documented for Halt { type Documentation = &'static zksync_error_description::ErrorDocumentation; - fn get_documentation( - &self, - ) -> Result, crate::documentation::DocumentationError> { + + fn get_documentation(&self) -> Result, crate::documentation::DocumentationError> { self.to_unified().get_identifier().get_documentation() } } -impl From for Halt { - fn from(value: anyhow::Error) -> Self { - let message = format!("{value:#?}"); - Halt::GenericError { message } + + +impl std::fmt::Display for Halt { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!("{self:?}")) } } + + +impl CustomErrorMessage for Halt { + fn get_message(&self) -> String { + match self { + Halt::ValidationFailed { + msg, + data, + } + => { format!("[anvil-halt-1] Account validation error: {msg}: {data}") }, + Halt::PaymasterValidationFailed { + msg, + data, + } + => { format!("[anvil-halt-2] Paymaster validation error: {msg}: {data}.") }, + Halt::PrePaymasterPreparationFailed { + msg, + data, + } + => { format!("[anvil-halt-3] Pre-paymaster preparation error: {msg}: {data}") }, + Halt::PayForTxFailed { + msg, + data, + } + => { format!("[anvil-halt-4] Failed to pay for the transaction: {msg}: {data}") }, + Halt::FailedToMarkFactoryDependencies { + msg, + data, + } + => { format!("[anvil-halt-5] Failed to mark factory dependencies: {msg}: {data}") }, + Halt::FailedToChargeFee { + msg, + data, + } + => { format!("[anvil-halt-6] Failed to charge fee: {msg}: {data}") }, + Halt::FromIsNotAnAccount { + } + => { format!("[anvil-halt-7] Sender is not an account") }, + Halt::InnerTxError { + } + => { format!("[anvil-halt-8] Bootloader-based tx failed") }, + Halt::Unknown { + msg, + data, + } + => { format!("[anvil-halt-9] Unknown reason: {msg}: {data}") }, + Halt::UnexpectedVMBehavior { + problem, + } + => { format!("[anvil-halt-10] virtual machine entered unexpected state. Error description: {problem}") }, + Halt::BootloaderOutOfGas { + } + => { format!("[anvil-halt-11] Bootloader out of gas") }, + Halt::ValidationOutOfGas { + } + => { format!("[anvil-halt-12] Validation run out of gas") }, + Halt::TooBigGasLimit { + } + => { format!("[anvil-halt-13] Transaction has a too big ergs limit and will not be executed by the server") }, + Halt::NotEnoughGasProvided { + } + => { format!("[anvil-halt-14] Bootloader did not have enough gas to start the transaction") }, + Halt::MissingInvocationLimitReached { + } + => { format!("[anvil-halt-15] Transaction produced too much storage accesses.") }, + Halt::FailedToSetL2Block { + msg, + } + => { format!("[anvil-halt-16] Failed to set information about the L2 block: {msg}") }, + Halt::FailedToAppendTransactionToL2Block { + msg, + } + => { format!("[anvil-halt-17] Failed to append the transaction to the current L2 block: {msg}") }, + Halt::VMPanic { + } + => { format!("[anvil-halt-18] VM panicked") }, + Halt::TracerCustom { + msg, + } + => { format!("[anvil-halt-19] Tracer aborted execution: {msg}") }, + Halt::FailedToPublishCompressedBytecodes { + } + => { format!("[anvil-halt-20] Failed to publish compressed bytecodes") }, + Halt::FailedBlockTimestampAssertion { + } + => { format!("[anvil-halt-21] Transaction failed `block.timestamp` assertion") }, + Halt::GenericError { + message, + } + => { format!("[anvil-halt-0] Generic error: {message}") }, + } + } +} + impl From for crate::packed::PackedError { fn from(value: Halt) -> Self { crate::packed::pack(value) } } + impl From for crate::serialized::SerializedError { fn from(value: Halt) -> Self { let packed = crate::packed::pack(value); crate::serialized::serialize(packed).expect("Internal serialization error.") } } -impl CustomErrorMessage for Halt { - fn get_message(&self) -> String { - match self { - Halt::ValidationFailed { msg, data } => { - format!("[anvil-halt-1] Account validation error: {msg}: {data}") - } - Halt::PaymasterValidationFailed { msg, data } => { - format!("[anvil-halt-2] Paymaster validation error: {msg}: {data}.") - } - Halt::PrePaymasterPreparationFailed { msg, data } => { - format!("[anvil-halt-3] Pre-paymaster preparation error: {msg}: {data}") - } - Halt::PayForTxFailed { msg, data } => { - format!("[anvil-halt-4] Failed to pay for the transaction: {msg}: {data}") - } - Halt::FailedToMarkFactoryDependencies { msg, data } => { - format!("[anvil-halt-5] Failed to mark factory dependencies: {msg}: {data}") - } - Halt::FailedToChargeFee { msg, data } => { - format!("[anvil-halt-6] Failed to charge fee: {msg}: {data}") - } - Halt::FromIsNotAnAccount => { - format!("[anvil-halt-7] Sender is not an account") - } - Halt::InnerTxError => { - format!("[anvil-halt-8] Bootloader-based tx failed") - } - Halt::Unknown { msg, data } => { - format!("[anvil-halt-9] Unknown reason: {msg}: {data}") - } - Halt::UnexpectedVMBehavior { problem } => { - format ! ("[anvil-halt-10] virtual machine entered unexpected state. Error description: {problem}") - } - Halt::BootloaderOutOfGas => { - format!("[anvil-halt-11] Bootloader out of gas") - } - Halt::ValidationOutOfGas => { - format!("[anvil-halt-12] Validation run out of gas") - } - Halt::TooBigGasLimit => { - format ! ("[anvil-halt-13] Transaction has a too big ergs limit and will not be executed by the server") - } - Halt::NotEnoughGasProvided => { - format!( - "[anvil-halt-14] Bootloader did not have enough gas to start the transaction" - ) - } - Halt::MissingInvocationLimitReached => { - format!("[anvil-halt-15] Transaction produced too much storage accesses.") - } - Halt::FailedToSetL2Block { msg } => { - format!("[anvil-halt-16] Failed to set information about the L2 block: {msg}") - } - Halt::FailedToAppendTransactionToL2Block { msg } => { - format ! ("[anvil-halt-17] Failed to append the transaction to the current L2 block: {msg}") - } - Halt::VMPanic => { - format!("[anvil-halt-18] VM panicked") - } - Halt::TracerCustom { msg } => { - format!("[anvil-halt-19] Tracer aborted execution: {msg}") - } - Halt::FailedToPublishCompressedBytecodes => { - format!("[anvil-halt-20] Failed to publish compressed bytecodes") - } - Halt::FailedBlockTimestampAssertion => { - format!("[anvil-halt-21] Transaction failed `block.timestamp` assertion") - } - Halt::GenericError { message } => { - format!("[anvil-halt-0] Generic error: {message}") - } - } - } -} -#[doc = ""] -#[doc = ""] -#[doc = "Domain: Anvil"] + #[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - Eq, - EnumDiscriminants, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] +#[derive(AsRefStr, Clone, Debug, Eq, EnumDiscriminants, PartialEq, serde::Serialize, serde::Deserialize)] #[strum_discriminants(name(RevertCode))] #[strum_discriminants(vis(pub))] #[strum_discriminants(derive(AsRefStr, FromRepr))] #[non_exhaustive] pub enum Revert { - #[doc = "# Summary "] - #[doc = "Execution reverted due to a failure."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "This error indicates that the transaction execution was reverted."] - General { - msg: String, - data: Vec, - } = 1u32, - #[doc = "# Summary "] - #[doc = "An inner transaction error occurred."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "This error is emitted when an inner transaction within the VM fails, typically related to bootloader execution."] - InnerTxError = 2u32, - #[doc = "# Summary "] - #[doc = "A generic VM error."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "This error indicates a generic failure within the VM, without specific details."] - VmError = 3u32, - #[doc = "# Summary "] - #[doc = "An unknown VM revert reason was encountered."] - #[doc = ""] - #[doc = "# Description"] - #[doc = "This error is emitted when the VM encounters a revert reason that is not recognized, including the function selector and raw data for debugging."] - Unknown { - function_selector: String, - data: String, - } = 4u32, - GenericError { - message: String, - } = 0u32, -} + /// # Short description + /// Execution reverted due to a failure. + /// + /// # Description + /// This error indicates that the transaction execution was reverted. + General { + msg : String, + data : Vec, + } = 1, + /// # Short description + /// An inner transaction error occurred. + /// + /// # Description + /// This error is emitted when an inner transaction within the VM fails, typically related to bootloader execution. + InnerTxError = 2, + /// # Short description + /// A generic VM error. + /// + /// # Description + /// This error indicates a generic failure within the VM, without specific details. + VmError = 3, + /// # Short description + /// An unknown VM revert reason was encountered. + /// + /// # Description + /// This error is emitted when the VM encounters a revert reason that is not recognized, including the function selector and raw data for debugging. + Unknown { + function_selector : String, + data : String, + } = 4, + GenericError { + message : String, + } = 0, + +} // end of Revert + + impl std::error::Error for Revert {} + impl NamedError for Revert { fn get_error_name(&self) -> String { self.as_ref().to_owned() @@ -374,87 +382,87 @@ impl NamedError for RevertCode { self.as_ref().to_owned() } } + impl From for crate::ZksyncError { fn from(val: Revert) -> Self { val.to_unified() } } -impl std::fmt::Display for Revert { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("{self:?}")) - } -} + + impl Documented for Revert { type Documentation = &'static zksync_error_description::ErrorDocumentation; - fn get_documentation( - &self, - ) -> Result, crate::documentation::DocumentationError> { + + fn get_documentation(&self) -> Result, crate::documentation::DocumentationError> { self.to_unified().get_identifier().get_documentation() } } -impl From for Revert { - fn from(value: anyhow::Error) -> Self { - let message = format!("{value:#?}"); - Revert::GenericError { message } + + +impl std::fmt::Display for Revert { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!("{self:?}")) } } + + +impl CustomErrorMessage for Revert { + fn get_message(&self) -> String { + match self { + Revert::General { + msg, + data, + } + => { format!("[anvil-revert-1] General revert error: {msg}") }, + Revert::InnerTxError { + } + => { format!("[anvil-revert-2] Bootloader-based transaction failed.") }, + Revert::VmError { + } + => { format!("[anvil-revert-3] VM Error") }, + Revert::Unknown { + function_selector, + data, + } + => { format!("[anvil-revert-4] Unknown VM revert reason: function_selector={function_selector}, data={data}") }, + Revert::GenericError { + message, + } + => { format!("[anvil-revert-0] Generic error: {message}") }, + } + } +} + impl From for crate::packed::PackedError { fn from(value: Revert) -> Self { crate::packed::pack(value) } } + impl From for crate::serialized::SerializedError { fn from(value: Revert) -> Self { let packed = crate::packed::pack(value); crate::serialized::serialize(packed).expect("Internal serialization error.") } } -impl CustomErrorMessage for Revert { - fn get_message(&self) -> String { - match self { - Revert::General { msg, data } => { - format!("[anvil-revert-1] General revert error: {msg}") - } - Revert::InnerTxError => { - format!("[anvil-revert-2] Bootloader-based transaction failed.") - } - Revert::VmError => { - format!("[anvil-revert-3] VM Error") - } - Revert::Unknown { - function_selector, - data, - } => { - format ! ("[anvil-revert-4] Unknown VM revert reason: function_selector={function_selector}, data={data}") - } - Revert::GenericError { message } => { - format!("[anvil-revert-0] Generic error: {message}") - } - } - } -} -#[doc = "Errors originating in the compiler backend for Ethereum VM (EVM)."] -#[doc = ""] -#[doc = "Domain: Compiler"] +/// Errors originating in the compiler backend for Ethereum VM (EVM). + #[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - Eq, - EnumDiscriminants, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] +#[derive(AsRefStr, Clone, Debug, Eq, EnumDiscriminants, PartialEq, serde::Serialize, serde::Deserialize)] #[strum_discriminants(name(LLVM_EVMCode))] #[strum_discriminants(vis(pub))] #[strum_discriminants(derive(AsRefStr, FromRepr))] #[non_exhaustive] pub enum LLVM_EVM { - GenericError { message: String } = 0u32, -} + GenericError { + message : String, + } = 0, + +} // end of LLVM_EVM + + impl std::error::Error for LLVM_EVM {} + impl NamedError for LLVM_EVM { fn get_error_name(&self) -> String { self.as_ref().to_owned() @@ -465,72 +473,71 @@ impl NamedError for LLVM_EVMCode { self.as_ref().to_owned() } } + impl From for crate::ZksyncError { fn from(val: LLVM_EVM) -> Self { val.to_unified() } } -impl std::fmt::Display for LLVM_EVM { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("{self:?}")) - } -} + + impl Documented for LLVM_EVM { type Documentation = &'static zksync_error_description::ErrorDocumentation; - fn get_documentation( - &self, - ) -> Result, crate::documentation::DocumentationError> { + + fn get_documentation(&self) -> Result, crate::documentation::DocumentationError> { self.to_unified().get_identifier().get_documentation() } } -impl From for LLVM_EVM { - fn from(value: anyhow::Error) -> Self { - let message = format!("{value:#?}"); - LLVM_EVM::GenericError { message } + + +impl std::fmt::Display for LLVM_EVM { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!("{self:?}")) } } + + +impl CustomErrorMessage for LLVM_EVM { + fn get_message(&self) -> String { + match self { + LLVM_EVM::GenericError { + message, + } + => { format!("[compiler-llvm+evm-0] Generic error: {message}") }, + } + } +} + impl From for crate::packed::PackedError { fn from(value: LLVM_EVM) -> Self { crate::packed::pack(value) } } + impl From for crate::serialized::SerializedError { fn from(value: LLVM_EVM) -> Self { let packed = crate::packed::pack(value); crate::serialized::serialize(packed).expect("Internal serialization error.") } } -impl CustomErrorMessage for LLVM_EVM { - fn get_message(&self) -> String { - match self { - LLVM_EVM::GenericError { message } => { - format!("[compiler-llvm+evm-0] Generic error: {message}") - } - } - } -} -#[doc = "Errors originating in the compiler backend for EraVM."] -#[doc = ""] -#[doc = "Domain: Compiler"] +/// Errors originating in the compiler backend for EraVM. + #[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - Eq, - EnumDiscriminants, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] +#[derive(AsRefStr, Clone, Debug, Eq, EnumDiscriminants, PartialEq, serde::Serialize, serde::Deserialize)] #[strum_discriminants(name(LLVM_EraCode))] #[strum_discriminants(vis(pub))] #[strum_discriminants(derive(AsRefStr, FromRepr))] #[non_exhaustive] pub enum LLVM_Era { - GenericError { message: String } = 0u32, -} + GenericError { + message : String, + } = 0, + +} // end of LLVM_Era + + impl std::error::Error for LLVM_Era {} + impl NamedError for LLVM_Era { fn get_error_name(&self) -> String { self.as_ref().to_owned() @@ -541,72 +548,71 @@ impl NamedError for LLVM_EraCode { self.as_ref().to_owned() } } + impl From for crate::ZksyncError { fn from(val: LLVM_Era) -> Self { val.to_unified() } } -impl std::fmt::Display for LLVM_Era { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("{self:?}")) - } -} + + impl Documented for LLVM_Era { type Documentation = &'static zksync_error_description::ErrorDocumentation; - fn get_documentation( - &self, - ) -> Result, crate::documentation::DocumentationError> { + + fn get_documentation(&self) -> Result, crate::documentation::DocumentationError> { self.to_unified().get_identifier().get_documentation() } } -impl From for LLVM_Era { - fn from(value: anyhow::Error) -> Self { - let message = format!("{value:#?}"); - LLVM_Era::GenericError { message } + + +impl std::fmt::Display for LLVM_Era { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!("{self:?}")) } } + + +impl CustomErrorMessage for LLVM_Era { + fn get_message(&self) -> String { + match self { + LLVM_Era::GenericError { + message, + } + => { format!("[compiler-llvm+era-0] Generic error: {message}") }, + } + } +} + impl From for crate::packed::PackedError { fn from(value: LLVM_Era) -> Self { crate::packed::pack(value) } } + impl From for crate::serialized::SerializedError { fn from(value: LLVM_Era) -> Self { let packed = crate::packed::pack(value); crate::serialized::serialize(packed).expect("Internal serialization error.") } } -impl CustomErrorMessage for LLVM_Era { - fn get_message(&self) -> String { - match self { - LLVM_Era::GenericError { message } => { - format!("[compiler-llvm+era-0] Generic error: {message}") - } - } - } -} -#[doc = "Errors originating in the official Solidity compiler."] -#[doc = ""] -#[doc = "Domain: Compiler"] +/// Errors originating in the official Solidity compiler. + #[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - Eq, - EnumDiscriminants, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] +#[derive(AsRefStr, Clone, Debug, Eq, EnumDiscriminants, PartialEq, serde::Serialize, serde::Deserialize)] #[strum_discriminants(name(SolcCode))] #[strum_discriminants(vis(pub))] #[strum_discriminants(derive(AsRefStr, FromRepr))] #[non_exhaustive] pub enum Solc { - GenericError { message: String } = 0u32, -} + GenericError { + message : String, + } = 0, + +} // end of Solc + + impl std::error::Error for Solc {} + impl NamedError for Solc { fn get_error_name(&self) -> String { self.as_ref().to_owned() @@ -617,72 +623,71 @@ impl NamedError for SolcCode { self.as_ref().to_owned() } } + impl From for crate::ZksyncError { fn from(val: Solc) -> Self { val.to_unified() } } -impl std::fmt::Display for Solc { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("{self:?}")) - } -} + + impl Documented for Solc { type Documentation = &'static zksync_error_description::ErrorDocumentation; - fn get_documentation( - &self, - ) -> Result, crate::documentation::DocumentationError> { + + fn get_documentation(&self) -> Result, crate::documentation::DocumentationError> { self.to_unified().get_identifier().get_documentation() } } -impl From for Solc { - fn from(value: anyhow::Error) -> Self { - let message = format!("{value:#?}"); - Solc::GenericError { message } + + +impl std::fmt::Display for Solc { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!("{self:?}")) } } + + +impl CustomErrorMessage for Solc { + fn get_message(&self) -> String { + match self { + Solc::GenericError { + message, + } + => { format!("[compiler-solc-0] Generic error: {message}") }, + } + } +} + impl From for crate::packed::PackedError { fn from(value: Solc) -> Self { crate::packed::pack(value) } } + impl From for crate::serialized::SerializedError { fn from(value: Solc) -> Self { let packed = crate::packed::pack(value); crate::serialized::serialize(packed).expect("Internal serialization error.") } } -impl CustomErrorMessage for Solc { - fn get_message(&self) -> String { - match self { - Solc::GenericError { message } => { - format!("[compiler-solc-0] Generic error: {message}") - } - } - } -} -#[doc = "Errors originating in the ZKsync fork of Solidity compiler."] -#[doc = ""] -#[doc = "Domain: Compiler"] +/// Errors originating in the ZKsync fork of Solidity compiler. + #[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - Eq, - EnumDiscriminants, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] +#[derive(AsRefStr, Clone, Debug, Eq, EnumDiscriminants, PartialEq, serde::Serialize, serde::Deserialize)] #[strum_discriminants(name(SolcForkCode))] #[strum_discriminants(vis(pub))] #[strum_discriminants(derive(AsRefStr, FromRepr))] #[non_exhaustive] pub enum SolcFork { - GenericError { message: String } = 0u32, -} + GenericError { + message : String, + } = 0, + +} // end of SolcFork + + impl std::error::Error for SolcFork {} + impl NamedError for SolcFork { fn get_error_name(&self) -> String { self.as_ref().to_owned() @@ -693,72 +698,71 @@ impl NamedError for SolcForkCode { self.as_ref().to_owned() } } + impl From for crate::ZksyncError { fn from(val: SolcFork) -> Self { val.to_unified() } } -impl std::fmt::Display for SolcFork { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("{self:?}")) - } -} + + impl Documented for SolcFork { type Documentation = &'static zksync_error_description::ErrorDocumentation; - fn get_documentation( - &self, - ) -> Result, crate::documentation::DocumentationError> { + + fn get_documentation(&self) -> Result, crate::documentation::DocumentationError> { self.to_unified().get_identifier().get_documentation() } } -impl From for SolcFork { - fn from(value: anyhow::Error) -> Self { - let message = format!("{value:#?}"); - SolcFork::GenericError { message } + + +impl std::fmt::Display for SolcFork { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!("{self:?}")) } } + + +impl CustomErrorMessage for SolcFork { + fn get_message(&self) -> String { + match self { + SolcFork::GenericError { + message, + } + => { format!("[compiler-solc+fork-0] Generic error: {message}") }, + } + } +} + impl From for crate::packed::PackedError { fn from(value: SolcFork) -> Self { crate::packed::pack(value) } } + impl From for crate::serialized::SerializedError { fn from(value: SolcFork) -> Self { let packed = crate::packed::pack(value); crate::serialized::serialize(packed).expect("Internal serialization error.") } } -impl CustomErrorMessage for SolcFork { - fn get_message(&self) -> String { - match self { - SolcFork::GenericError { message } => { - format!("[compiler-solc+fork-0] Generic error: {message}") - } - } - } -} -#[doc = "Errors originating in the ZKsync Solidity compiler for EraVM and EVM."] -#[doc = ""] -#[doc = "Domain: Compiler"] +/// Errors originating in the ZKsync Solidity compiler for EraVM and EVM. + #[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - Eq, - EnumDiscriminants, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] +#[derive(AsRefStr, Clone, Debug, Eq, EnumDiscriminants, PartialEq, serde::Serialize, serde::Deserialize)] #[strum_discriminants(name(ZksolcCode))] #[strum_discriminants(vis(pub))] #[strum_discriminants(derive(AsRefStr, FromRepr))] #[non_exhaustive] pub enum Zksolc { - GenericError { message: String } = 0u32, -} + GenericError { + message : String, + } = 0, + +} // end of Zksolc + + impl std::error::Error for Zksolc {} + impl NamedError for Zksolc { fn get_error_name(&self) -> String { self.as_ref().to_owned() @@ -769,72 +773,71 @@ impl NamedError for ZksolcCode { self.as_ref().to_owned() } } + impl From for crate::ZksyncError { fn from(val: Zksolc) -> Self { val.to_unified() } } -impl std::fmt::Display for Zksolc { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("{self:?}")) - } -} + + impl Documented for Zksolc { type Documentation = &'static zksync_error_description::ErrorDocumentation; - fn get_documentation( - &self, - ) -> Result, crate::documentation::DocumentationError> { + + fn get_documentation(&self) -> Result, crate::documentation::DocumentationError> { self.to_unified().get_identifier().get_documentation() } } -impl From for Zksolc { - fn from(value: anyhow::Error) -> Self { - let message = format!("{value:#?}"); - Zksolc::GenericError { message } + + +impl std::fmt::Display for Zksolc { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!("{self:?}")) } } + + +impl CustomErrorMessage for Zksolc { + fn get_message(&self) -> String { + match self { + Zksolc::GenericError { + message, + } + => { format!("[compiler-zksolc-0] Generic error: {message}") }, + } + } +} + impl From for crate::packed::PackedError { fn from(value: Zksolc) -> Self { crate::packed::pack(value) } } + impl From for crate::serialized::SerializedError { fn from(value: Zksolc) -> Self { let packed = crate::packed::pack(value); crate::serialized::serialize(packed).expect("Internal serialization error.") } } -impl CustomErrorMessage for Zksolc { - fn get_message(&self) -> String { - match self { - Zksolc::GenericError { message } => { - format!("[compiler-zksolc-0] Generic error: {message}") - } - } - } -} -#[doc = "Errors originating in the ZKsync Vyper compiler for EraVM."] -#[doc = ""] -#[doc = "Domain: Compiler"] +/// Errors originating in the ZKsync Vyper compiler for EraVM. + #[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - Eq, - EnumDiscriminants, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] +#[derive(AsRefStr, Clone, Debug, Eq, EnumDiscriminants, PartialEq, serde::Serialize, serde::Deserialize)] #[strum_discriminants(name(ZkvyperCode))] #[strum_discriminants(vis(pub))] #[strum_discriminants(derive(AsRefStr, FromRepr))] #[non_exhaustive] pub enum Zkvyper { - GenericError { message: String } = 0u32, -} + GenericError { + message : String, + } = 0, + +} // end of Zkvyper + + impl std::error::Error for Zkvyper {} + impl NamedError for Zkvyper { fn get_error_name(&self) -> String { self.as_ref().to_owned() @@ -845,72 +848,71 @@ impl NamedError for ZkvyperCode { self.as_ref().to_owned() } } + impl From for crate::ZksyncError { fn from(val: Zkvyper) -> Self { val.to_unified() } } -impl std::fmt::Display for Zkvyper { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("{self:?}")) - } -} + + impl Documented for Zkvyper { type Documentation = &'static zksync_error_description::ErrorDocumentation; - fn get_documentation( - &self, - ) -> Result, crate::documentation::DocumentationError> { + + fn get_documentation(&self) -> Result, crate::documentation::DocumentationError> { self.to_unified().get_identifier().get_documentation() } } -impl From for Zkvyper { - fn from(value: anyhow::Error) -> Self { - let message = format!("{value:#?}"); - Zkvyper::GenericError { message } + + +impl std::fmt::Display for Zkvyper { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!("{self:?}")) } } + + +impl CustomErrorMessage for Zkvyper { + fn get_message(&self) -> String { + match self { + Zkvyper::GenericError { + message, + } + => { format!("[compiler-zkvyper-0] Generic error: {message}") }, + } + } +} + impl From for crate::packed::PackedError { fn from(value: Zkvyper) -> Self { crate::packed::pack(value) } } + impl From for crate::serialized::SerializedError { fn from(value: Zkvyper) -> Self { let packed = crate::packed::pack(value); crate::serialized::serialize(packed).expect("Internal serialization error.") } } -impl CustomErrorMessage for Zkvyper { - fn get_message(&self) -> String { - match self { - Zkvyper::GenericError { message } => { - format!("[compiler-zkvyper-0] Generic error: {message}") - } - } - } -} -#[doc = "Errors originating in the web3 API."] -#[doc = ""] -#[doc = "Domain: Core"] +/// Errors originating in the web3 API. + #[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - Eq, - EnumDiscriminants, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] +#[derive(AsRefStr, Clone, Debug, Eq, EnumDiscriminants, PartialEq, serde::Serialize, serde::Deserialize)] #[strum_discriminants(name(APICode))] #[strum_discriminants(vis(pub))] #[strum_discriminants(derive(AsRefStr, FromRepr))] #[non_exhaustive] pub enum API { - GenericError { message: String } = 0u32, -} + GenericError { + message : String, + } = 0, + +} // end of API + + impl std::error::Error for API {} + impl NamedError for API { fn get_error_name(&self) -> String { self.as_ref().to_owned() @@ -921,72 +923,71 @@ impl NamedError for APICode { self.as_ref().to_owned() } } + impl From for crate::ZksyncError { fn from(val: API) -> Self { val.to_unified() } } -impl std::fmt::Display for API { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("{self:?}")) - } -} + + impl Documented for API { type Documentation = &'static zksync_error_description::ErrorDocumentation; - fn get_documentation( - &self, - ) -> Result, crate::documentation::DocumentationError> { + + fn get_documentation(&self) -> Result, crate::documentation::DocumentationError> { self.to_unified().get_identifier().get_documentation() } } -impl From for API { - fn from(value: anyhow::Error) -> Self { - let message = format!("{value:#?}"); - API::GenericError { message } + + +impl std::fmt::Display for API { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!("{self:?}")) } } + + +impl CustomErrorMessage for API { + fn get_message(&self) -> String { + match self { + API::GenericError { + message, + } + => { format!("[core-api-0] Generic error: {message}") }, + } + } +} + impl From for crate::packed::PackedError { fn from(value: API) -> Self { crate::packed::pack(value) } } + impl From for crate::serialized::SerializedError { fn from(value: API) -> Self { let packed = crate::packed::pack(value); crate::serialized::serialize(packed).expect("Internal serialization error.") } } -impl CustomErrorMessage for API { - fn get_message(&self) -> String { - match self { - API::GenericError { message } => { - format!("[core-api-0] Generic error: {message}") - } - } - } -} -#[doc = "Errors in EraVM virtual machine executing contracts."] -#[doc = ""] -#[doc = "Domain: Core"] +/// Errors in EraVM virtual machine executing contracts. + #[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - Eq, - EnumDiscriminants, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] +#[derive(AsRefStr, Clone, Debug, Eq, EnumDiscriminants, PartialEq, serde::Serialize, serde::Deserialize)] #[strum_discriminants(name(EraVMCode))] #[strum_discriminants(vis(pub))] #[strum_discriminants(derive(AsRefStr, FromRepr))] #[non_exhaustive] pub enum EraVM { - GenericError { message: String } = 0u32, -} + GenericError { + message : String, + } = 0, + +} // end of EraVM + + impl std::error::Error for EraVM {} + impl NamedError for EraVM { fn get_error_name(&self) -> String { self.as_ref().to_owned() @@ -997,72 +998,71 @@ impl NamedError for EraVMCode { self.as_ref().to_owned() } } + impl From for crate::ZksyncError { fn from(val: EraVM) -> Self { val.to_unified() } } -impl std::fmt::Display for EraVM { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("{self:?}")) - } -} + + impl Documented for EraVM { type Documentation = &'static zksync_error_description::ErrorDocumentation; - fn get_documentation( - &self, - ) -> Result, crate::documentation::DocumentationError> { + + fn get_documentation(&self) -> Result, crate::documentation::DocumentationError> { self.to_unified().get_identifier().get_documentation() } } -impl From for EraVM { - fn from(value: anyhow::Error) -> Self { - let message = format!("{value:#?}"); - EraVM::GenericError { message } + + +impl std::fmt::Display for EraVM { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!("{self:?}")) } } + + +impl CustomErrorMessage for EraVM { + fn get_message(&self) -> String { + match self { + EraVM::GenericError { + message, + } + => { format!("[core-eravm-0] Generic error: {message}") }, + } + } +} + impl From for crate::packed::PackedError { fn from(value: EraVM) -> Self { crate::packed::pack(value) } } + impl From for crate::serialized::SerializedError { fn from(value: EraVM) -> Self { let packed = crate::packed::pack(value); crate::serialized::serialize(packed).expect("Internal serialization error.") } } -impl CustomErrorMessage for EraVM { - fn get_message(&self) -> String { - match self { - EraVM::GenericError { message } => { - format!("[core-eravm-0] Generic error: {message}") - } - } - } -} -#[doc = "Errors in the contract execution environment, bootloader, etc."] -#[doc = ""] -#[doc = "Domain: Core"] +/// Errors in the contract execution environment, bootloader, etc. + #[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - Eq, - EnumDiscriminants, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] +#[derive(AsRefStr, Clone, Debug, Eq, EnumDiscriminants, PartialEq, serde::Serialize, serde::Deserialize)] #[strum_discriminants(name(ExecutionPlatformCode))] #[strum_discriminants(vis(pub))] #[strum_discriminants(derive(AsRefStr, FromRepr))] #[non_exhaustive] pub enum ExecutionPlatform { - GenericError { message: String } = 0u32, -} + GenericError { + message : String, + } = 0, + +} // end of ExecutionPlatform + + impl std::error::Error for ExecutionPlatform {} + impl NamedError for ExecutionPlatform { fn get_error_name(&self) -> String { self.as_ref().to_owned() @@ -1073,73 +1073,74 @@ impl NamedError for ExecutionPlatformCode { self.as_ref().to_owned() } } + impl From for crate::ZksyncError { fn from(val: ExecutionPlatform) -> Self { val.to_unified() } } -impl std::fmt::Display for ExecutionPlatform { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("{self:?}")) - } -} + + impl Documented for ExecutionPlatform { type Documentation = &'static zksync_error_description::ErrorDocumentation; - fn get_documentation( - &self, - ) -> Result, crate::documentation::DocumentationError> { + + fn get_documentation(&self) -> Result, crate::documentation::DocumentationError> { self.to_unified().get_identifier().get_documentation() } } -impl From for ExecutionPlatform { - fn from(value: anyhow::Error) -> Self { - let message = format!("{value:#?}"); - ExecutionPlatform::GenericError { message } + + +impl std::fmt::Display for ExecutionPlatform { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!("{self:?}")) } } + + +impl CustomErrorMessage for ExecutionPlatform { + fn get_message(&self) -> String { + match self { + ExecutionPlatform::GenericError { + message, + } + => { format!("[core-exec-0] Generic error: {message}") }, + } + } +} + impl From for crate::packed::PackedError { fn from(value: ExecutionPlatform) -> Self { crate::packed::pack(value) } } + impl From for crate::serialized::SerializedError { fn from(value: ExecutionPlatform) -> Self { let packed = crate::packed::pack(value); crate::serialized::serialize(packed).expect("Internal serialization error.") } } -impl CustomErrorMessage for ExecutionPlatform { - fn get_message(&self) -> String { - match self { - ExecutionPlatform::GenericError { message } => { - format!("[core-exec-0] Generic error: {message}") - } - } - } -} -#[doc = "Errors in the sequencer node"] -#[doc = ""] -#[doc = "Domain: Core"] +/// Errors in the sequencer node + #[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - Eq, - EnumDiscriminants, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] +#[derive(AsRefStr, Clone, Debug, Eq, EnumDiscriminants, PartialEq, serde::Serialize, serde::Deserialize)] #[strum_discriminants(name(SequencerCode))] #[strum_discriminants(vis(pub))] #[strum_discriminants(derive(AsRefStr, FromRepr))] #[non_exhaustive] pub enum Sequencer { - GenericSequencerError { message: String } = 1u32, - GenericError { message: String } = 0u32, -} + GenericSequencerError { + message : String, + } = 1, + GenericError { + message : String, + } = 0, + +} // end of Sequencer + + impl std::error::Error for Sequencer {} + impl NamedError for Sequencer { fn get_error_name(&self) -> String { self.as_ref().to_owned() @@ -1150,75 +1151,75 @@ impl NamedError for SequencerCode { self.as_ref().to_owned() } } + impl From for crate::ZksyncError { fn from(val: Sequencer) -> Self { val.to_unified() } } -impl std::fmt::Display for Sequencer { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("{self:?}")) - } -} + + impl Documented for Sequencer { type Documentation = &'static zksync_error_description::ErrorDocumentation; - fn get_documentation( - &self, - ) -> Result, crate::documentation::DocumentationError> { + + fn get_documentation(&self) -> Result, crate::documentation::DocumentationError> { self.to_unified().get_identifier().get_documentation() } } -impl From for Sequencer { - fn from(value: anyhow::Error) -> Self { - let message = format!("{value:#?}"); - Sequencer::GenericError { message } + + +impl std::fmt::Display for Sequencer { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!("{self:?}")) } } + + +impl CustomErrorMessage for Sequencer { + fn get_message(&self) -> String { + match self { + Sequencer::GenericSequencerError { + message, + } + => { format!("[core-seq-1] Generic error: {message}") }, + Sequencer::GenericError { + message, + } + => { format!("[core-seq-0] Generic error: {message}") }, + } + } +} + impl From for crate::packed::PackedError { fn from(value: Sequencer) -> Self { crate::packed::pack(value) } } + impl From for crate::serialized::SerializedError { fn from(value: Sequencer) -> Self { let packed = crate::packed::pack(value); crate::serialized::serialize(packed).expect("Internal serialization error.") } } -impl CustomErrorMessage for Sequencer { - fn get_message(&self) -> String { - match self { - Sequencer::GenericSequencerError { message } => { - format!("[core-seq-1] Generic error: {message}") - } - Sequencer::GenericError { message } => { - format!("[core-seq-0] Generic error: {message}") - } - } - } -} -#[doc = "Errors originating in the upstream Foundry implementation."] -#[doc = ""] -#[doc = "Domain: Foundry"] +/// Errors originating in the upstream Foundry implementation. + #[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - Eq, - EnumDiscriminants, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] +#[derive(AsRefStr, Clone, Debug, Eq, EnumDiscriminants, PartialEq, serde::Serialize, serde::Deserialize)] #[strum_discriminants(name(FoundryUpstreamCode))] #[strum_discriminants(vis(pub))] #[strum_discriminants(derive(AsRefStr, FromRepr))] #[non_exhaustive] pub enum FoundryUpstream { - GenericError { message: String } = 0u32, -} + GenericError { + message : String, + } = 0, + +} // end of FoundryUpstream + + impl std::error::Error for FoundryUpstream {} + impl NamedError for FoundryUpstream { fn get_error_name(&self) -> String { self.as_ref().to_owned() @@ -1229,72 +1230,71 @@ impl NamedError for FoundryUpstreamCode { self.as_ref().to_owned() } } + impl From for crate::ZksyncError { fn from(val: FoundryUpstream) -> Self { val.to_unified() } } -impl std::fmt::Display for FoundryUpstream { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("{self:?}")) - } -} + + impl Documented for FoundryUpstream { type Documentation = &'static zksync_error_description::ErrorDocumentation; - fn get_documentation( - &self, - ) -> Result, crate::documentation::DocumentationError> { + + fn get_documentation(&self) -> Result, crate::documentation::DocumentationError> { self.to_unified().get_identifier().get_documentation() } } -impl From for FoundryUpstream { - fn from(value: anyhow::Error) -> Self { - let message = format!("{value:#?}"); - FoundryUpstream::GenericError { message } + + +impl std::fmt::Display for FoundryUpstream { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!("{self:?}")) } } + + +impl CustomErrorMessage for FoundryUpstream { + fn get_message(&self) -> String { + match self { + FoundryUpstream::GenericError { + message, + } + => { format!("[foundry-upstream-0] Generic error: {message}") }, + } + } +} + impl From for crate::packed::PackedError { fn from(value: FoundryUpstream) -> Self { crate::packed::pack(value) } } + impl From for crate::serialized::SerializedError { fn from(value: FoundryUpstream) -> Self { let packed = crate::packed::pack(value); crate::serialized::serialize(packed).expect("Internal serialization error.") } } -impl CustomErrorMessage for FoundryUpstream { - fn get_message(&self) -> String { - match self { - FoundryUpstream::GenericError { message } => { - format!("[foundry-upstream-0] Generic error: {message}") - } - } - } -} -#[doc = "Errors originating in the ZKsync codebase for Foundry."] -#[doc = ""] -#[doc = "Domain: Foundry"] +/// Errors originating in the ZKsync codebase for Foundry. + #[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - Eq, - EnumDiscriminants, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] +#[derive(AsRefStr, Clone, Debug, Eq, EnumDiscriminants, PartialEq, serde::Serialize, serde::Deserialize)] #[strum_discriminants(name(FoundryZksyncCode))] #[strum_discriminants(vis(pub))] #[strum_discriminants(derive(AsRefStr, FromRepr))] #[non_exhaustive] pub enum FoundryZksync { - GenericError { message: String } = 0u32, -} + GenericError { + message : String, + } = 0, + +} // end of FoundryZksync + + impl std::error::Error for FoundryZksync {} + impl NamedError for FoundryZksync { fn get_error_name(&self) -> String { self.as_ref().to_owned() @@ -1305,72 +1305,71 @@ impl NamedError for FoundryZksyncCode { self.as_ref().to_owned() } } + impl From for crate::ZksyncError { fn from(val: FoundryZksync) -> Self { val.to_unified() } } -impl std::fmt::Display for FoundryZksync { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("{self:?}")) - } -} + + impl Documented for FoundryZksync { type Documentation = &'static zksync_error_description::ErrorDocumentation; - fn get_documentation( - &self, - ) -> Result, crate::documentation::DocumentationError> { + + fn get_documentation(&self) -> Result, crate::documentation::DocumentationError> { self.to_unified().get_identifier().get_documentation() } } -impl From for FoundryZksync { - fn from(value: anyhow::Error) -> Self { - let message = format!("{value:#?}"); - FoundryZksync::GenericError { message } + + +impl std::fmt::Display for FoundryZksync { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!("{self:?}")) } } + + +impl CustomErrorMessage for FoundryZksync { + fn get_message(&self) -> String { + match self { + FoundryZksync::GenericError { + message, + } + => { format!("[foundry-zksync-0] Generic error: {message}") }, + } + } +} + impl From for crate::packed::PackedError { fn from(value: FoundryZksync) -> Self { crate::packed::pack(value) } } + impl From for crate::serialized::SerializedError { fn from(value: FoundryZksync) -> Self { let packed = crate::packed::pack(value); crate::serialized::serialize(packed).expect("Internal serialization error.") } } -impl CustomErrorMessage for FoundryZksync { - fn get_message(&self) -> String { - match self { - FoundryZksync::GenericError { message } => { - format!("[foundry-zksync-0] Generic error: {message}") - } - } - } -} -#[doc = "Errors originating in the upstream Hardhat implementation."] -#[doc = ""] -#[doc = "Domain: Hardhat"] +/// Errors originating in the upstream Hardhat implementation. + #[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - Eq, - EnumDiscriminants, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] +#[derive(AsRefStr, Clone, Debug, Eq, EnumDiscriminants, PartialEq, serde::Serialize, serde::Deserialize)] #[strum_discriminants(name(HardhatUpstreamCode))] #[strum_discriminants(vis(pub))] #[strum_discriminants(derive(AsRefStr, FromRepr))] #[non_exhaustive] pub enum HardhatUpstream { - GenericError { message: String } = 0u32, -} + GenericError { + message : String, + } = 0, + +} // end of HardhatUpstream + + impl std::error::Error for HardhatUpstream {} + impl NamedError for HardhatUpstream { fn get_error_name(&self) -> String { self.as_ref().to_owned() @@ -1381,72 +1380,71 @@ impl NamedError for HardhatUpstreamCode { self.as_ref().to_owned() } } + impl From for crate::ZksyncError { fn from(val: HardhatUpstream) -> Self { val.to_unified() } } -impl std::fmt::Display for HardhatUpstream { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("{self:?}")) - } -} + + impl Documented for HardhatUpstream { type Documentation = &'static zksync_error_description::ErrorDocumentation; - fn get_documentation( - &self, - ) -> Result, crate::documentation::DocumentationError> { + + fn get_documentation(&self) -> Result, crate::documentation::DocumentationError> { self.to_unified().get_identifier().get_documentation() } } -impl From for HardhatUpstream { - fn from(value: anyhow::Error) -> Self { - let message = format!("{value:#?}"); - HardhatUpstream::GenericError { message } + + +impl std::fmt::Display for HardhatUpstream { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!("{self:?}")) } } + + +impl CustomErrorMessage for HardhatUpstream { + fn get_message(&self) -> String { + match self { + HardhatUpstream::GenericError { + message, + } + => { format!("[hardhat-upstream-0] Generic error: {message}") }, + } + } +} + impl From for crate::packed::PackedError { fn from(value: HardhatUpstream) -> Self { crate::packed::pack(value) } } + impl From for crate::serialized::SerializedError { fn from(value: HardhatUpstream) -> Self { let packed = crate::packed::pack(value); crate::serialized::serialize(packed).expect("Internal serialization error.") } } -impl CustomErrorMessage for HardhatUpstream { - fn get_message(&self) -> String { - match self { - HardhatUpstream::GenericError { message } => { - format!("[hardhat-upstream-0] Generic error: {message}") - } - } - } -} -#[doc = "Errors originating in the ZKsync codebase for HardHat."] -#[doc = ""] -#[doc = "Domain: Hardhat"] +/// Errors originating in the ZKsync codebase for HardHat. + #[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - Eq, - EnumDiscriminants, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] +#[derive(AsRefStr, Clone, Debug, Eq, EnumDiscriminants, PartialEq, serde::Serialize, serde::Deserialize)] #[strum_discriminants(name(HardhatZksyncCode))] #[strum_discriminants(vis(pub))] #[strum_discriminants(derive(AsRefStr, FromRepr))] #[non_exhaustive] pub enum HardhatZksync { - GenericError { message: String } = 0u32, -} + GenericError { + message : String, + } = 0, + +} // end of HardhatZksync + + impl std::error::Error for HardhatZksync {} + impl NamedError for HardhatZksync { fn get_error_name(&self) -> String { self.as_ref().to_owned() @@ -1457,47 +1455,50 @@ impl NamedError for HardhatZksyncCode { self.as_ref().to_owned() } } + impl From for crate::ZksyncError { fn from(val: HardhatZksync) -> Self { val.to_unified() } } -impl std::fmt::Display for HardhatZksync { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("{self:?}")) - } -} + + impl Documented for HardhatZksync { type Documentation = &'static zksync_error_description::ErrorDocumentation; - fn get_documentation( - &self, - ) -> Result, crate::documentation::DocumentationError> { + + fn get_documentation(&self) -> Result, crate::documentation::DocumentationError> { self.to_unified().get_identifier().get_documentation() } } -impl From for HardhatZksync { - fn from(value: anyhow::Error) -> Self { - let message = format!("{value:#?}"); - HardhatZksync::GenericError { message } + + +impl std::fmt::Display for HardhatZksync { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!("{self:?}")) } } + + +impl CustomErrorMessage for HardhatZksync { + fn get_message(&self) -> String { + match self { + HardhatZksync::GenericError { + message, + } + => { format!("[hardhat-zksync-0] Generic error: {message}") }, + } + } +} + impl From for crate::packed::PackedError { fn from(value: HardhatZksync) -> Self { crate::packed::pack(value) } } + impl From for crate::serialized::SerializedError { fn from(value: HardhatZksync) -> Self { let packed = crate::packed::pack(value); crate::serialized::serialize(packed).expect("Internal serialization error.") } } -impl CustomErrorMessage for HardhatZksync { - fn get_message(&self) -> String { - match self { - HardhatZksync::GenericError { message } => { - format!("[hardhat-zksync-0] Generic error: {message}") - } - } - } -} diff --git a/crates/zksync_error/src/error/domains.rs b/crates/zksync_error/src/error/domains.rs index bb41566a..10d97c39 100644 --- a/crates/zksync_error/src/error/domains.rs +++ b/crates/zksync_error/src/error/domains.rs @@ -1,30 +1,23 @@ + //! //! AUTOGENERATED BASED ON A SET OF JSON FILES, DO NOT EDIT MANUALLY //! #![allow(non_camel_case_types)] -use crate::error::definitions::APICode; -use crate::error::definitions::EraVM; -use crate::error::definitions::EraVMCode; -use crate::error::definitions::ExecutionPlatform; -use crate::error::definitions::ExecutionPlatformCode; -use crate::error::definitions::FoundryUpstream; -use crate::error::definitions::FoundryUpstreamCode; -use crate::error::definitions::FoundryZksync; -use crate::error::definitions::FoundryZksyncCode; +use crate::error::ICustomError; +use crate::error::IUnifiedError; +use crate::kind::Kind; +use strum_macros::AsRefStr; +use strum_macros::EnumDiscriminants; +use strum_macros::FromRepr; use crate::error::definitions::Halt; use crate::error::definitions::HaltCode; -use crate::error::definitions::HardhatUpstream; -use crate::error::definitions::HardhatUpstreamCode; -use crate::error::definitions::HardhatZksync; -use crate::error::definitions::HardhatZksyncCode; +use crate::error::definitions::Revert; +use crate::error::definitions::RevertCode; +use crate::error::definitions::LLVM_EVM; use crate::error::definitions::LLVM_EVMCode; use crate::error::definitions::LLVM_Era; use crate::error::definitions::LLVM_EraCode; -use crate::error::definitions::Revert; -use crate::error::definitions::RevertCode; -use crate::error::definitions::Sequencer; -use crate::error::definitions::SequencerCode; use crate::error::definitions::Solc; use crate::error::definitions::SolcCode; use crate::error::definitions::SolcFork; @@ -34,128 +27,103 @@ use crate::error::definitions::ZksolcCode; use crate::error::definitions::Zkvyper; use crate::error::definitions::ZkvyperCode; use crate::error::definitions::API; -use crate::error::definitions::LLVM_EVM; -use crate::error::ICustomError; -use crate::error::IUnifiedError; -use crate::kind::Kind; -use strum_macros::AsRefStr; -use strum_macros::EnumDiscriminants; -use strum_macros::FromRepr; +use crate::error::definitions::APICode; +use crate::error::definitions::EraVM; +use crate::error::definitions::EraVMCode; +use crate::error::definitions::ExecutionPlatform; +use crate::error::definitions::ExecutionPlatformCode; +use crate::error::definitions::Sequencer; +use crate::error::definitions::SequencerCode; +use crate::error::definitions::FoundryUpstream; +use crate::error::definitions::FoundryUpstreamCode; +use crate::error::definitions::FoundryZksync; +use crate::error::definitions::FoundryZksyncCode; +use crate::error::definitions::HardhatUpstream; +use crate::error::definitions::HardhatUpstreamCode; +use crate::error::definitions::HardhatZksync; +use crate::error::definitions::HardhatZksyncCode; + #[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - EnumDiscriminants, - Eq, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] +#[derive(AsRefStr, Clone, Debug, EnumDiscriminants, Eq, PartialEq, serde::Serialize, serde::Deserialize)] pub enum ZksyncError { - Anvil(Anvil), - Compiler(Compiler), - Core(Core), - Foundry(Foundry), - Hardhat(Hardhat), + Anvil(Anvil), + Compiler(Compiler), + Core(Core), + Foundry(Foundry), + Hardhat(Hardhat), } + impl crate::documentation::Documented for ZksyncError { type Documentation = &'static zksync_error_description::ErrorDocumentation; - fn get_documentation( - &self, - ) -> Result, crate::documentation::DocumentationError> { + + fn get_documentation(&self) -> Result, crate::documentation::DocumentationError> { match self { - ZksyncError::Anvil(Anvil::Halt(error)) => error.get_documentation(), - ZksyncError::Anvil(Anvil::Revert(error)) => error.get_documentation(), - ZksyncError::Compiler(Compiler::LLVM_EVM(error)) => error.get_documentation(), - ZksyncError::Compiler(Compiler::LLVM_Era(error)) => error.get_documentation(), - ZksyncError::Compiler(Compiler::Solc(error)) => error.get_documentation(), - ZksyncError::Compiler(Compiler::SolcFork(error)) => error.get_documentation(), - ZksyncError::Compiler(Compiler::Zksolc(error)) => error.get_documentation(), - ZksyncError::Compiler(Compiler::Zkvyper(error)) => error.get_documentation(), - ZksyncError::Core(Core::API(error)) => error.get_documentation(), - ZksyncError::Core(Core::EraVM(error)) => error.get_documentation(), - ZksyncError::Core(Core::ExecutionPlatform(error)) => error.get_documentation(), - ZksyncError::Core(Core::Sequencer(error)) => error.get_documentation(), - ZksyncError::Foundry(Foundry::FoundryUpstream(error)) => error.get_documentation(), - ZksyncError::Foundry(Foundry::FoundryZksync(error)) => error.get_documentation(), - ZksyncError::Hardhat(Hardhat::HardhatUpstream(error)) => error.get_documentation(), - ZksyncError::Hardhat(Hardhat::HardhatZksync(error)) => error.get_documentation(), - } - } + + ZksyncError::Anvil(Anvil::Halt(error)) => error.get_documentation() , + ZksyncError::Anvil(Anvil::Revert(error)) => error.get_documentation() , + ZksyncError::Compiler(Compiler::LLVM_EVM(error)) => error.get_documentation() , + ZksyncError::Compiler(Compiler::LLVM_Era(error)) => error.get_documentation() , + ZksyncError::Compiler(Compiler::Solc(error)) => error.get_documentation() , + ZksyncError::Compiler(Compiler::SolcFork(error)) => error.get_documentation() , + ZksyncError::Compiler(Compiler::Zksolc(error)) => error.get_documentation() , + ZksyncError::Compiler(Compiler::Zkvyper(error)) => error.get_documentation() , + ZksyncError::Core(Core::API(error)) => error.get_documentation() , + ZksyncError::Core(Core::EraVM(error)) => error.get_documentation() , + ZksyncError::Core(Core::ExecutionPlatform(error)) => error.get_documentation() , + ZksyncError::Core(Core::Sequencer(error)) => error.get_documentation() , + ZksyncError::Foundry(Foundry::FoundryUpstream(error)) => error.get_documentation() , + ZksyncError::Foundry(Foundry::FoundryZksync(error)) => error.get_documentation() , + ZksyncError::Hardhat(Hardhat::HardhatUpstream(error)) => error.get_documentation() , + ZksyncError::Hardhat(Hardhat::HardhatZksync(error)) => error.get_documentation() , + } + } } + impl ZksyncError { + pub fn get_kind(&self) -> crate::kind::Kind { match self { - ZksyncError::Anvil(Anvil::Halt(_)) => Kind::Anvil(AnvilCode::Halt), - ZksyncError::Anvil(Anvil::Revert(_)) => Kind::Anvil(AnvilCode::Revert), - ZksyncError::Compiler(Compiler::LLVM_EVM(_)) => Kind::Compiler(CompilerCode::LLVM_EVM), - ZksyncError::Compiler(Compiler::LLVM_Era(_)) => Kind::Compiler(CompilerCode::LLVM_Era), - ZksyncError::Compiler(Compiler::Solc(_)) => Kind::Compiler(CompilerCode::Solc), - ZksyncError::Compiler(Compiler::SolcFork(_)) => Kind::Compiler(CompilerCode::SolcFork), - ZksyncError::Compiler(Compiler::Zksolc(_)) => Kind::Compiler(CompilerCode::Zksolc), - ZksyncError::Compiler(Compiler::Zkvyper(_)) => Kind::Compiler(CompilerCode::Zkvyper), - ZksyncError::Core(Core::API(_)) => Kind::Core(CoreCode::API), - ZksyncError::Core(Core::EraVM(_)) => Kind::Core(CoreCode::EraVM), - ZksyncError::Core(Core::ExecutionPlatform(_)) => { - Kind::Core(CoreCode::ExecutionPlatform) - } - ZksyncError::Core(Core::Sequencer(_)) => Kind::Core(CoreCode::Sequencer), - ZksyncError::Foundry(Foundry::FoundryUpstream(_)) => { - Kind::Foundry(FoundryCode::FoundryUpstream) - } - ZksyncError::Foundry(Foundry::FoundryZksync(_)) => { - Kind::Foundry(FoundryCode::FoundryZksync) - } - ZksyncError::Hardhat(Hardhat::HardhatUpstream(_)) => { - Kind::Hardhat(HardhatCode::HardhatUpstream) - } - ZksyncError::Hardhat(Hardhat::HardhatZksync(_)) => { - Kind::Hardhat(HardhatCode::HardhatZksync) - } - } - } + ZksyncError::Anvil(Anvil::Halt(_)) => { Kind::Anvil(AnvilCode::Halt) }, + ZksyncError::Anvil(Anvil::Revert(_)) => { Kind::Anvil(AnvilCode::Revert) }, + ZksyncError::Compiler(Compiler::LLVM_EVM(_)) => { Kind::Compiler(CompilerCode::LLVM_EVM) }, + ZksyncError::Compiler(Compiler::LLVM_Era(_)) => { Kind::Compiler(CompilerCode::LLVM_Era) }, + ZksyncError::Compiler(Compiler::Solc(_)) => { Kind::Compiler(CompilerCode::Solc) }, + ZksyncError::Compiler(Compiler::SolcFork(_)) => { Kind::Compiler(CompilerCode::SolcFork) }, + ZksyncError::Compiler(Compiler::Zksolc(_)) => { Kind::Compiler(CompilerCode::Zksolc) }, + ZksyncError::Compiler(Compiler::Zkvyper(_)) => { Kind::Compiler(CompilerCode::Zkvyper) }, + ZksyncError::Core(Core::API(_)) => { Kind::Core(CoreCode::API) }, + ZksyncError::Core(Core::EraVM(_)) => { Kind::Core(CoreCode::EraVM) }, + ZksyncError::Core(Core::ExecutionPlatform(_)) => { Kind::Core(CoreCode::ExecutionPlatform) }, + ZksyncError::Core(Core::Sequencer(_)) => { Kind::Core(CoreCode::Sequencer) }, + ZksyncError::Foundry(Foundry::FoundryUpstream(_)) => { Kind::Foundry(FoundryCode::FoundryUpstream) }, + ZksyncError::Foundry(Foundry::FoundryZksync(_)) => { Kind::Foundry(FoundryCode::FoundryZksync) }, + ZksyncError::Hardhat(Hardhat::HardhatUpstream(_)) => { Kind::Hardhat(HardhatCode::HardhatUpstream) }, + ZksyncError::Hardhat(Hardhat::HardhatZksync(_)) => { Kind::Hardhat(HardhatCode::HardhatZksync) }, + } + } + pub fn get_code(&self) -> u32 { match self { - ZksyncError::Anvil(Anvil::Halt(error)) => Into::::into(error) as u32, - ZksyncError::Anvil(Anvil::Revert(error)) => Into::::into(error) as u32, - ZksyncError::Compiler(Compiler::LLVM_EVM(error)) => { - Into::::into(error) as u32 - } - ZksyncError::Compiler(Compiler::LLVM_Era(error)) => { - Into::::into(error) as u32 - } - ZksyncError::Compiler(Compiler::Solc(error)) => Into::::into(error) as u32, - ZksyncError::Compiler(Compiler::SolcFork(error)) => { - Into::::into(error) as u32 - } - ZksyncError::Compiler(Compiler::Zksolc(error)) => { - Into::::into(error) as u32 - } - ZksyncError::Compiler(Compiler::Zkvyper(error)) => { - Into::::into(error) as u32 - } - ZksyncError::Core(Core::API(error)) => Into::::into(error) as u32, - ZksyncError::Core(Core::EraVM(error)) => Into::::into(error) as u32, - ZksyncError::Core(Core::ExecutionPlatform(error)) => { - Into::::into(error) as u32 - } - ZksyncError::Core(Core::Sequencer(error)) => Into::::into(error) as u32, - ZksyncError::Foundry(Foundry::FoundryUpstream(error)) => { - Into::::into(error) as u32 - } - ZksyncError::Foundry(Foundry::FoundryZksync(error)) => { - Into::::into(error) as u32 - } - ZksyncError::Hardhat(Hardhat::HardhatUpstream(error)) => { - Into::::into(error) as u32 - } - ZksyncError::Hardhat(Hardhat::HardhatZksync(error)) => { - Into::::into(error) as u32 - } - } - } + ZksyncError::Anvil(Anvil::Halt(error)) => { Into::::into(error) as u32 }, + ZksyncError::Anvil(Anvil::Revert(error)) => { Into::::into(error) as u32 }, + ZksyncError::Compiler(Compiler::LLVM_EVM(error)) => { Into::::into(error) as u32 }, + ZksyncError::Compiler(Compiler::LLVM_Era(error)) => { Into::::into(error) as u32 }, + ZksyncError::Compiler(Compiler::Solc(error)) => { Into::::into(error) as u32 }, + ZksyncError::Compiler(Compiler::SolcFork(error)) => { Into::::into(error) as u32 }, + ZksyncError::Compiler(Compiler::Zksolc(error)) => { Into::::into(error) as u32 }, + ZksyncError::Compiler(Compiler::Zkvyper(error)) => { Into::::into(error) as u32 }, + ZksyncError::Core(Core::API(error)) => { Into::::into(error) as u32 }, + ZksyncError::Core(Core::EraVM(error)) => { Into::::into(error) as u32 }, + ZksyncError::Core(Core::ExecutionPlatform(error)) => { Into::::into(error) as u32 }, + ZksyncError::Core(Core::Sequencer(error)) => { Into::::into(error) as u32 }, + ZksyncError::Foundry(Foundry::FoundryUpstream(error)) => { Into::::into(error) as u32 }, + ZksyncError::Foundry(Foundry::FoundryZksync(error)) => { Into::::into(error) as u32 }, + ZksyncError::Hardhat(Hardhat::HardhatUpstream(error)) => { Into::::into(error) as u32 }, + ZksyncError::Hardhat(Hardhat::HardhatZksync(error)) => { Into::::into(error) as u32 }, + } + } } + impl std::fmt::Display for ZksyncError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_fmt(format_args!("{:#?}", self)) @@ -163,204 +131,212 @@ impl std::fmt::Display for ZksyncError { } impl IUnifiedError for ZksyncError {} impl std::error::Error for ZksyncError {} + + #[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - EnumDiscriminants, - Eq, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] +#[derive(AsRefStr, Clone, Debug, EnumDiscriminants, Eq, PartialEq, serde::Serialize, serde::Deserialize)] #[strum_discriminants(name(AnvilCode))] #[strum_discriminants(derive(serde::Serialize, serde::Deserialize, FromRepr))] #[strum_discriminants(vis(pub))] pub enum Anvil { - Halt(Halt), - Revert(Revert), + Halt(Halt), + Revert(Revert), } + impl Anvil { pub fn get_name(&self) -> &str { self.as_ref() } } -impl ICustomError for Halt { - fn to_unified(&self) -> ZksyncError { - ZksyncError::Anvil(Anvil::Halt(self.clone())) + + + +#[repr(u32)] +#[derive(AsRefStr, Clone, Debug, EnumDiscriminants, Eq, PartialEq, serde::Serialize, serde::Deserialize)] +#[strum_discriminants(name(CompilerCode))] +#[strum_discriminants(derive(serde::Serialize, serde::Deserialize, FromRepr))] +#[strum_discriminants(vis(pub))] +pub enum Compiler { + LLVM_EVM(LLVM_EVM), + LLVM_Era(LLVM_Era), + Solc(Solc), + SolcFork(SolcFork), + Zksolc(Zksolc), + Zkvyper(Zkvyper), +} + +impl Compiler { + pub fn get_name(&self) -> &str { + self.as_ref() } } -impl ICustomError for Revert { - fn to_unified(&self) -> ZksyncError { - ZksyncError::Anvil(Anvil::Revert(self.clone())) + + + +#[repr(u32)] +#[derive(AsRefStr, Clone, Debug, EnumDiscriminants, Eq, PartialEq, serde::Serialize, serde::Deserialize)] +#[strum_discriminants(name(CoreCode))] +#[strum_discriminants(derive(serde::Serialize, serde::Deserialize, FromRepr))] +#[strum_discriminants(vis(pub))] +pub enum Core { + API(API), + EraVM(EraVM), + ExecutionPlatform(ExecutionPlatform), + Sequencer(Sequencer), +} + +impl Core { + pub fn get_name(&self) -> &str { + self.as_ref() } } + + + #[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - EnumDiscriminants, - Eq, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] -#[strum_discriminants(name(CompilerCode))] +#[derive(AsRefStr, Clone, Debug, EnumDiscriminants, Eq, PartialEq, serde::Serialize, serde::Deserialize)] +#[strum_discriminants(name(FoundryCode))] #[strum_discriminants(derive(serde::Serialize, serde::Deserialize, FromRepr))] #[strum_discriminants(vis(pub))] -pub enum Compiler { - LLVM_EVM(LLVM_EVM), - LLVM_Era(LLVM_Era), - Solc(Solc), - SolcFork(SolcFork), - Zksolc(Zksolc), - Zkvyper(Zkvyper), +pub enum Foundry { + FoundryUpstream(FoundryUpstream), + FoundryZksync(FoundryZksync), } -impl Compiler { + +impl Foundry { pub fn get_name(&self) -> &str { self.as_ref() } } + + + +#[repr(u32)] +#[derive(AsRefStr, Clone, Debug, EnumDiscriminants, Eq, PartialEq, serde::Serialize, serde::Deserialize)] +#[strum_discriminants(name(HardhatCode))] +#[strum_discriminants(derive(serde::Serialize, serde::Deserialize, FromRepr))] +#[strum_discriminants(vis(pub))] +pub enum Hardhat { + HardhatUpstream(HardhatUpstream), + HardhatZksync(HardhatZksync), +} + +impl Hardhat { + pub fn get_name(&self) -> &str { + self.as_ref() + } +} + + + +impl ICustomError for Halt { + fn to_unified(&self) -> ZksyncError { + ZksyncError::Anvil(Anvil::Halt(self.clone())) + } +} + + +impl ICustomError for Revert { + fn to_unified(&self) -> ZksyncError { + ZksyncError::Anvil(Anvil::Revert(self.clone())) + } +} + + impl ICustomError for LLVM_EVM { fn to_unified(&self) -> ZksyncError { ZksyncError::Compiler(Compiler::LLVM_EVM(self.clone())) } } + + impl ICustomError for LLVM_Era { fn to_unified(&self) -> ZksyncError { ZksyncError::Compiler(Compiler::LLVM_Era(self.clone())) } } + + impl ICustomError for Solc { fn to_unified(&self) -> ZksyncError { ZksyncError::Compiler(Compiler::Solc(self.clone())) } } + + impl ICustomError for SolcFork { fn to_unified(&self) -> ZksyncError { ZksyncError::Compiler(Compiler::SolcFork(self.clone())) } } + + impl ICustomError for Zksolc { fn to_unified(&self) -> ZksyncError { ZksyncError::Compiler(Compiler::Zksolc(self.clone())) } } + + impl ICustomError for Zkvyper { fn to_unified(&self) -> ZksyncError { ZksyncError::Compiler(Compiler::Zkvyper(self.clone())) } } -#[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - EnumDiscriminants, - Eq, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] -#[strum_discriminants(name(CoreCode))] -#[strum_discriminants(derive(serde::Serialize, serde::Deserialize, FromRepr))] -#[strum_discriminants(vis(pub))] -pub enum Core { - API(API), - EraVM(EraVM), - ExecutionPlatform(ExecutionPlatform), - Sequencer(Sequencer), -} -impl Core { - pub fn get_name(&self) -> &str { - self.as_ref() - } -} + + impl ICustomError for API { fn to_unified(&self) -> ZksyncError { ZksyncError::Core(Core::API(self.clone())) } } + + impl ICustomError for EraVM { fn to_unified(&self) -> ZksyncError { ZksyncError::Core(Core::EraVM(self.clone())) } } + + impl ICustomError for ExecutionPlatform { fn to_unified(&self) -> ZksyncError { ZksyncError::Core(Core::ExecutionPlatform(self.clone())) } } + + impl ICustomError for Sequencer { fn to_unified(&self) -> ZksyncError { ZksyncError::Core(Core::Sequencer(self.clone())) } } -#[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - EnumDiscriminants, - Eq, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] -#[strum_discriminants(name(FoundryCode))] -#[strum_discriminants(derive(serde::Serialize, serde::Deserialize, FromRepr))] -#[strum_discriminants(vis(pub))] -pub enum Foundry { - FoundryUpstream(FoundryUpstream), - FoundryZksync(FoundryZksync), -} -impl Foundry { - pub fn get_name(&self) -> &str { - self.as_ref() - } -} + + impl ICustomError for FoundryUpstream { fn to_unified(&self) -> ZksyncError { ZksyncError::Foundry(Foundry::FoundryUpstream(self.clone())) } } + + impl ICustomError for FoundryZksync { fn to_unified(&self) -> ZksyncError { ZksyncError::Foundry(Foundry::FoundryZksync(self.clone())) } } -#[repr(u32)] -#[derive( - AsRefStr, - Clone, - Debug, - EnumDiscriminants, - Eq, - PartialEq, - serde :: Serialize, - serde :: Deserialize, -)] -#[strum_discriminants(name(HardhatCode))] -#[strum_discriminants(derive(serde::Serialize, serde::Deserialize, FromRepr))] -#[strum_discriminants(vis(pub))] -pub enum Hardhat { - HardhatUpstream(HardhatUpstream), - HardhatZksync(HardhatZksync), -} -impl Hardhat { - pub fn get_name(&self) -> &str { - self.as_ref() - } -} + + impl ICustomError for HardhatUpstream { fn to_unified(&self) -> ZksyncError { ZksyncError::Hardhat(Hardhat::HardhatUpstream(self.clone())) } } + + impl ICustomError for HardhatZksync { fn to_unified(&self) -> ZksyncError { ZksyncError::Hardhat(Hardhat::HardhatZksync(self.clone())) } } + diff --git a/crates/zksync_error/src/error/mod.rs b/crates/zksync_error/src/error/mod.rs index f41a92de..171b11f4 100644 --- a/crates/zksync_error/src/error/mod.rs +++ b/crates/zksync_error/src/error/mod.rs @@ -1,17 +1,21 @@ + //! //! AUTOGENERATED BASED ON A SET OF JSON FILES, DO NOT EDIT MANUALLY //! pub mod definitions; pub mod domains; + +use std::error::Error; +use crate::identifier::Identifier; +use crate::error::domains::ZksyncError; + use crate::error::domains::Anvil; use crate::error::domains::Compiler; use crate::error::domains::Core; use crate::error::domains::Foundry; use crate::error::domains::Hardhat; -use crate::error::domains::ZksyncError; -use crate::identifier::Identifier; -use std::error::Error; + pub trait IError: Error where ContainedType: Clone, @@ -20,12 +24,14 @@ where fn get_message(&self) -> String; fn get_data(&self) -> ContainedType; } + pub trait IUnifiedError: serde::Serialize + for<'de> serde::Deserialize<'de> + IError where ContainedType: Clone, { } + pub trait ICustomError where U: IUnifiedError, @@ -33,12 +39,15 @@ where { fn to_unified(&self) -> U; } + pub trait CustomErrorMessage { fn get_message(&self) -> String; } + pub trait NamedError { fn get_error_name(&self) -> String; } + impl IError for ZksyncError { fn get_identifier(&self) -> Identifier { Identifier { @@ -46,26 +55,29 @@ impl IError for ZksyncError { code: self.get_code(), } } + fn get_message(&self) -> String { match self { - ZksyncError::Anvil(Anvil::Halt(error)) => error.get_message(), - ZksyncError::Anvil(Anvil::Revert(error)) => error.get_message(), - ZksyncError::Compiler(Compiler::LLVM_EVM(error)) => error.get_message(), - ZksyncError::Compiler(Compiler::LLVM_Era(error)) => error.get_message(), - ZksyncError::Compiler(Compiler::Solc(error)) => error.get_message(), - ZksyncError::Compiler(Compiler::SolcFork(error)) => error.get_message(), - ZksyncError::Compiler(Compiler::Zksolc(error)) => error.get_message(), - ZksyncError::Compiler(Compiler::Zkvyper(error)) => error.get_message(), - ZksyncError::Core(Core::API(error)) => error.get_message(), - ZksyncError::Core(Core::EraVM(error)) => error.get_message(), - ZksyncError::Core(Core::ExecutionPlatform(error)) => error.get_message(), - ZksyncError::Core(Core::Sequencer(error)) => error.get_message(), - ZksyncError::Foundry(Foundry::FoundryUpstream(error)) => error.get_message(), - ZksyncError::Foundry(Foundry::FoundryZksync(error)) => error.get_message(), - ZksyncError::Hardhat(Hardhat::HardhatUpstream(error)) => error.get_message(), - ZksyncError::Hardhat(Hardhat::HardhatZksync(error)) => error.get_message(), + ZksyncError::Anvil(Anvil::Halt(error)) => error.get_message(), + ZksyncError::Anvil(Anvil::Revert(error)) => error.get_message(), + ZksyncError::Compiler(Compiler::LLVM_EVM(error)) => error.get_message(), + ZksyncError::Compiler(Compiler::LLVM_Era(error)) => error.get_message(), + ZksyncError::Compiler(Compiler::Solc(error)) => error.get_message(), + ZksyncError::Compiler(Compiler::SolcFork(error)) => error.get_message(), + ZksyncError::Compiler(Compiler::Zksolc(error)) => error.get_message(), + ZksyncError::Compiler(Compiler::Zkvyper(error)) => error.get_message(), + ZksyncError::Core(Core::API(error)) => error.get_message(), + ZksyncError::Core(Core::EraVM(error)) => error.get_message(), + ZksyncError::Core(Core::ExecutionPlatform(error)) => error.get_message(), + ZksyncError::Core(Core::Sequencer(error)) => error.get_message(), + ZksyncError::Foundry(Foundry::FoundryUpstream(error)) => error.get_message(), + ZksyncError::Foundry(Foundry::FoundryZksync(error)) => error.get_message(), + ZksyncError::Hardhat(Hardhat::HardhatUpstream(error)) => error.get_message(), + ZksyncError::Hardhat(Hardhat::HardhatZksync(error)) => error.get_message(), + } } + fn get_data(&self) -> ZksyncError { self.clone() } diff --git a/crates/zksync_error/src/identifier.rs b/crates/zksync_error/src/identifier.rs index 8543fbe2..2af4cc3a 100644 --- a/crates/zksync_error/src/identifier.rs +++ b/crates/zksync_error/src/identifier.rs @@ -1,25 +1,29 @@ + //! //! AUTOGENERATED BASED ON A SET OF JSON FILES, DO NOT EDIT MANUALLY //! - use crate::error::domains::AnvilCode; use crate::error::domains::CompilerCode; use crate::error::domains::CoreCode; use crate::error::domains::FoundryCode; use crate::error::domains::HardhatCode; + use crate::error::NamedError; use crate::kind::DomainCode; use crate::kind::Kind; -#[derive(Clone, Debug, Eq, PartialEq, serde :: Deserialize, serde :: Serialize)] + +#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)] pub struct StructuredErrorCode { pub domain_code: u32, pub component_code: u32, pub error_code: u32, } + impl StructuredErrorCode { pub fn encode(&self) -> u32 { self.domain_code * 10000 + self.component_code * 1000 + self.error_code } + pub fn decode(raw_code: u32) -> Self { let error_code = raw_code % 1000; let component_code = (raw_code / 1000) % 10; @@ -31,167 +35,121 @@ impl StructuredErrorCode { } } } -#[derive(Clone, Debug, Eq, PartialEq, serde :: Deserialize, serde :: Serialize)] + + +#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)] pub struct Identifier { pub kind: Kind, pub code: u32, } + impl Identifier { pub fn new(kind: Kind, code: u32) -> Self { Self { kind, code } } + pub fn encode(&self) -> u32 { let domain_code: u32 = self.kind.domain_code(); let component_code: u32 = self.kind.component_code(); domain_code * 10000 + component_code * 1000 + self.code } + pub fn decode(code: StructuredErrorCode) -> Option { - let StructuredErrorCode { - domain_code, - component_code, - error_code, - } = code; + let StructuredErrorCode { domain_code, component_code, error_code } = code; let domain = DomainCode::from_repr(domain_code)?; let kind: Kind = match domain { - DomainCode::Anvil => Kind::Anvil(AnvilCode::from_repr(component_code)?), - DomainCode::Compiler => Kind::Compiler(CompilerCode::from_repr(component_code)?), - DomainCode::Core => Kind::Core(CoreCode::from_repr(component_code)?), - DomainCode::Foundry => Kind::Foundry(FoundryCode::from_repr(component_code)?), - DomainCode::Hardhat => Kind::Hardhat(HardhatCode::from_repr(component_code)?), - }; - Some(Identifier { - kind, - code: error_code, - }) + + DomainCode::Anvil => { + Kind::Anvil(AnvilCode::from_repr(component_code)?) + }, + DomainCode::Compiler => { + Kind::Compiler(CompilerCode::from_repr(component_code)?) + }, + DomainCode::Core => { + Kind::Core(CoreCode::from_repr(component_code)?) + }, + DomainCode::Foundry => { + Kind::Foundry(FoundryCode::from_repr(component_code)?) + }, + DomainCode::Hardhat => { + Kind::Hardhat(HardhatCode::from_repr(component_code)?) + }, + + }; + Some(Identifier { kind, code: error_code }) } } -pub trait Identifying { - fn get_identifier_repr(&self) -> String; -} -impl Identifying for Identifier { - fn get_identifier_repr(&self) -> String { - format!("[{}-{}]", self.kind.get_identifier_repr(), self.code) - } + + +trait Identifying { + fn get_identifier_repr(&self)-> String; } + + impl Identifying for Kind { + fn get_identifier_repr(&self) -> String { + match self { + Kind::Anvil(AnvilCode::Halt) => "anvil-halt", + Kind::Anvil(AnvilCode::Revert) => "anvil-revert", + Kind::Compiler(CompilerCode::LLVM_EVM) => "compiler-llvm+evm", + Kind::Compiler(CompilerCode::LLVM_Era) => "compiler-llvm+era", + Kind::Compiler(CompilerCode::Solc) => "compiler-solc", + Kind::Compiler(CompilerCode::SolcFork) => "compiler-solc+fork", + Kind::Compiler(CompilerCode::Zksolc) => "compiler-zksolc", + Kind::Compiler(CompilerCode::Zkvyper) => "compiler-zkvyper", + Kind::Core(CoreCode::API) => "core-api", + Kind::Core(CoreCode::EraVM) => "core-eravm", + Kind::Core(CoreCode::ExecutionPlatform) => "core-exec", + Kind::Core(CoreCode::Sequencer) => "core-seq", + Kind::Foundry(FoundryCode::FoundryUpstream) => "foundry-upstream", + Kind::Foundry(FoundryCode::FoundryZksync) => "foundry-zksync", + Kind::Hardhat(HardhatCode::HardhatUpstream) => "hardhat-upstream", + Kind::Hardhat(HardhatCode::HardhatZksync) => "hardhat-zksync", + + }.into() + } +} + +impl Identifying for Identifier { fn get_identifier_repr(&self) -> String { - match self { - Kind::Anvil(AnvilCode::Halt) => "anvil-halt", - Kind::Anvil(AnvilCode::Revert) => "anvil-revert", - Kind::Compiler(CompilerCode::LLVM_EVM) => "compiler-llvm+evm", - Kind::Compiler(CompilerCode::LLVM_Era) => "compiler-llvm+era", - Kind::Compiler(CompilerCode::Solc) => "compiler-solc", - Kind::Compiler(CompilerCode::SolcFork) => "compiler-solc+fork", - Kind::Compiler(CompilerCode::Zksolc) => "compiler-zksolc", - Kind::Compiler(CompilerCode::Zkvyper) => "compiler-zkvyper", - Kind::Core(CoreCode::API) => "core-api", - Kind::Core(CoreCode::EraVM) => "core-eravm", - Kind::Core(CoreCode::ExecutionPlatform) => "core-exec", - Kind::Core(CoreCode::Sequencer) => "core-seq", - Kind::Foundry(FoundryCode::FoundryUpstream) => "foundry-upstream", - Kind::Foundry(FoundryCode::FoundryZksync) => "foundry-zksync", - Kind::Hardhat(HardhatCode::HardhatUpstream) => "hardhat-upstream", - Kind::Hardhat(HardhatCode::HardhatZksync) => "hardhat-zksync", - } - .into() - } + format!("[{}-{}]", self.kind.get_identifier_repr(), self.code) + } } + impl NamedError for Identifier { fn get_error_name(&self) -> String { match self.kind { - Kind::Anvil(AnvilCode::Halt) => { - crate::error::definitions::HaltCode::from_repr(self.code) - .expect("Internal error") - .get_error_name() - } - Kind::Anvil(AnvilCode::Revert) => { - crate::error::definitions::RevertCode::from_repr(self.code) - .expect("Internal error") - .get_error_name() - } - Kind::Compiler(CompilerCode::LLVM_EVM) => { - crate::error::definitions::LLVM_EVMCode::from_repr(self.code) - .expect("Internal error") - .get_error_name() - } - Kind::Compiler(CompilerCode::LLVM_Era) => { - crate::error::definitions::LLVM_EraCode::from_repr(self.code) - .expect("Internal error") - .get_error_name() - } - Kind::Compiler(CompilerCode::Solc) => { - crate::error::definitions::SolcCode::from_repr(self.code) - .expect("Internal error") - .get_error_name() - } - Kind::Compiler(CompilerCode::SolcFork) => { - crate::error::definitions::SolcForkCode::from_repr(self.code) - .expect("Internal error") - .get_error_name() - } - Kind::Compiler(CompilerCode::Zksolc) => { - crate::error::definitions::ZksolcCode::from_repr(self.code) - .expect("Internal error") - .get_error_name() - } - Kind::Compiler(CompilerCode::Zkvyper) => { - crate::error::definitions::ZkvyperCode::from_repr(self.code) - .expect("Internal error") - .get_error_name() - } - Kind::Core(CoreCode::API) => crate::error::definitions::APICode::from_repr(self.code) - .expect("Internal error") - .get_error_name(), - Kind::Core(CoreCode::EraVM) => { - crate::error::definitions::EraVMCode::from_repr(self.code) - .expect("Internal error") - .get_error_name() - } - Kind::Core(CoreCode::ExecutionPlatform) => { - crate::error::definitions::ExecutionPlatformCode::from_repr(self.code) - .expect("Internal error") - .get_error_name() - } - Kind::Core(CoreCode::Sequencer) => { - crate::error::definitions::SequencerCode::from_repr(self.code) - .expect("Internal error") - .get_error_name() - } - Kind::Foundry(FoundryCode::FoundryUpstream) => { - crate::error::definitions::FoundryUpstreamCode::from_repr(self.code) - .expect("Internal error") - .get_error_name() - } - Kind::Foundry(FoundryCode::FoundryZksync) => { - crate::error::definitions::FoundryZksyncCode::from_repr(self.code) - .expect("Internal error") - .get_error_name() - } - Kind::Hardhat(HardhatCode::HardhatUpstream) => { - crate::error::definitions::HardhatUpstreamCode::from_repr(self.code) - .expect("Internal error") - .get_error_name() - } - Kind::Hardhat(HardhatCode::HardhatZksync) => { - crate::error::definitions::HardhatZksyncCode::from_repr(self.code) - .expect("Internal error") - .get_error_name() - } + Kind::Anvil(AnvilCode::Halt) => crate::error::definitions::HaltCode::from_repr(self.code).expect("Internal error").get_error_name(), + Kind::Anvil(AnvilCode::Revert) => crate::error::definitions::RevertCode::from_repr(self.code).expect("Internal error").get_error_name(), + Kind::Compiler(CompilerCode::LLVM_EVM) => crate::error::definitions::LLVM_EVMCode::from_repr(self.code).expect("Internal error").get_error_name(), + Kind::Compiler(CompilerCode::LLVM_Era) => crate::error::definitions::LLVM_EraCode::from_repr(self.code).expect("Internal error").get_error_name(), + Kind::Compiler(CompilerCode::Solc) => crate::error::definitions::SolcCode::from_repr(self.code).expect("Internal error").get_error_name(), + Kind::Compiler(CompilerCode::SolcFork) => crate::error::definitions::SolcForkCode::from_repr(self.code).expect("Internal error").get_error_name(), + Kind::Compiler(CompilerCode::Zksolc) => crate::error::definitions::ZksolcCode::from_repr(self.code).expect("Internal error").get_error_name(), + Kind::Compiler(CompilerCode::Zkvyper) => crate::error::definitions::ZkvyperCode::from_repr(self.code).expect("Internal error").get_error_name(), + Kind::Core(CoreCode::API) => crate::error::definitions::APICode::from_repr(self.code).expect("Internal error").get_error_name(), + Kind::Core(CoreCode::EraVM) => crate::error::definitions::EraVMCode::from_repr(self.code).expect("Internal error").get_error_name(), + Kind::Core(CoreCode::ExecutionPlatform) => crate::error::definitions::ExecutionPlatformCode::from_repr(self.code).expect("Internal error").get_error_name(), + Kind::Core(CoreCode::Sequencer) => crate::error::definitions::SequencerCode::from_repr(self.code).expect("Internal error").get_error_name(), + Kind::Foundry(FoundryCode::FoundryUpstream) => crate::error::definitions::FoundryUpstreamCode::from_repr(self.code).expect("Internal error").get_error_name(), + Kind::Foundry(FoundryCode::FoundryZksync) => crate::error::definitions::FoundryZksyncCode::from_repr(self.code).expect("Internal error").get_error_name(), + Kind::Hardhat(HardhatCode::HardhatUpstream) => crate::error::definitions::HardhatUpstreamCode::from_repr(self.code).expect("Internal error").get_error_name(), + Kind::Hardhat(HardhatCode::HardhatZksync) => crate::error::definitions::HardhatZksyncCode::from_repr(self.code).expect("Internal error").get_error_name(), + } } } + + impl crate::documentation::Documented for Identifier { type Documentation = &'static zksync_error_description::ErrorDocumentation; - fn get_documentation( - &self, - ) -> Result, crate::documentation::DocumentationError> { + fn get_documentation(&self) -> Result, crate::documentation::DocumentationError> { use crate::documentation::model; + let repr = &self.get_identifier_repr(); match model.errors.get(repr) { Some(metadata) => Ok(metadata.documentation.as_ref()), - None => Err(crate::documentation::DocumentationError::IncompleteModel( - format!("Can not fetch description for error {repr}."), - )), + None => Err(crate::documentation::DocumentationError::IncompleteModel(format!("Can not fetch description for error {repr}."))) } } } diff --git a/crates/zksync_error/src/kind.rs b/crates/zksync_error/src/kind.rs index c4cf400f..f97b5570 100644 --- a/crates/zksync_error/src/kind.rs +++ b/crates/zksync_error/src/kind.rs @@ -1,28 +1,29 @@ + //! //! AUTOGENERATED BASED ON A SET OF JSON FILES, DO NOT EDIT MANUALLY //! +use strum_macros::{EnumDiscriminants, FromRepr}; + use crate::error::domains::AnvilCode; use crate::error::domains::CompilerCode; use crate::error::domains::CoreCode; use crate::error::domains::FoundryCode; use crate::error::domains::HardhatCode; -use strum_macros::EnumDiscriminants; -use strum_macros::FromRepr; -#[derive( - Clone, Debug, EnumDiscriminants, Eq, PartialEq, serde :: Deserialize, serde :: Serialize, -)] + +#[derive(Clone, Debug, EnumDiscriminants, Eq, PartialEq, serde::Deserialize, serde::Serialize)] #[strum_discriminants(name(DomainCode))] #[strum_discriminants(derive(FromRepr))] #[strum_discriminants(vis(pub))] #[repr(u32)] pub enum Kind { - Anvil(AnvilCode) = 5u32, - Compiler(CompilerCode) = 2u32, - Core(CoreCode) = 1u32, - Foundry(FoundryCode) = 4u32, - Hardhat(HardhatCode) = 3u32, + Anvil(AnvilCode) = 5, + Compiler(CompilerCode) = 2, + Core(CoreCode) = 1, + Foundry(FoundryCode) = 4, + Hardhat(HardhatCode) = 3, } + impl Kind { pub fn domain_code(&self) -> u32 { let domain: DomainCode = self.clone().into(); @@ -30,11 +31,12 @@ impl Kind { } pub fn component_code(&self) -> u32 { match self { - Kind::Anvil(component) => component.clone() as u32, - Kind::Compiler(component) => component.clone() as u32, - Kind::Core(component) => component.clone() as u32, - Kind::Foundry(component) => component.clone() as u32, - Kind::Hardhat(component) => component.clone() as u32, + Kind::Anvil(component) => component.clone() as u32, + Kind::Compiler(component) => component.clone() as u32, + Kind::Core(component) => component.clone() as u32, + Kind::Foundry(component) => component.clone() as u32, + Kind::Hardhat(component) => component.clone() as u32, + } } } diff --git a/crates/zksync_error/src/lib.rs b/crates/zksync_error/src/lib.rs index 05111a39..77142b97 100644 --- a/crates/zksync_error/src/lib.rs +++ b/crates/zksync_error/src/lib.rs @@ -1,161 +1,246 @@ + //! //! AUTOGENERATED BASED ON A SET OF JSON FILES, DO NOT EDIT MANUALLY //! #![allow(unused)] -pub mod documentation; + pub mod error; pub mod identifier; pub mod kind; pub mod packed; pub mod serialized; pub mod untyped; +pub mod documentation; + + pub use crate::error::domains::ZksyncError; + pub mod anvil { - pub mod halt { - pub use crate::error::definitions::Halt as HaltError; - pub use crate::error::definitions::Halt::BootloaderOutOfGas; - pub use crate::error::definitions::Halt::FailedBlockTimestampAssertion; - pub use crate::error::definitions::Halt::FailedToAppendTransactionToL2Block; - pub use crate::error::definitions::Halt::FailedToChargeFee; - pub use crate::error::definitions::Halt::FailedToMarkFactoryDependencies; - pub use crate::error::definitions::Halt::FailedToPublishCompressedBytecodes; - pub use crate::error::definitions::Halt::FailedToSetL2Block; - pub use crate::error::definitions::Halt::FromIsNotAnAccount; - pub use crate::error::definitions::Halt::GenericError; - pub use crate::error::definitions::Halt::InnerTxError; - pub use crate::error::definitions::Halt::MissingInvocationLimitReached; - pub use crate::error::definitions::Halt::NotEnoughGasProvided; - pub use crate::error::definitions::Halt::PayForTxFailed; - pub use crate::error::definitions::Halt::PaymasterValidationFailed; - pub use crate::error::definitions::Halt::PrePaymasterPreparationFailed; - pub use crate::error::definitions::Halt::TooBigGasLimit; - pub use crate::error::definitions::Halt::TracerCustom; - pub use crate::error::definitions::Halt::UnexpectedVMBehavior; - pub use crate::error::definitions::Halt::Unknown; - pub use crate::error::definitions::Halt::VMPanic; - pub use crate::error::definitions::Halt::ValidationFailed; - pub use crate::error::definitions::Halt::ValidationOutOfGas; - #[macro_export] - macro_rules ! anvil_halt_generic_error { ($ ($ arg : tt) *) => { zksync_error :: error :: definitions :: Halt :: GenericError { message : format ! ($ ($ arg) *) } } ; } - pub use crate::anvil_halt_generic_error as generic_error; - } - pub mod revert { - pub use crate::error::definitions::Revert as RevertError; - pub use crate::error::definitions::Revert::General; - pub use crate::error::definitions::Revert::GenericError; - pub use crate::error::definitions::Revert::InnerTxError; - pub use crate::error::definitions::Revert::Unknown; - pub use crate::error::definitions::Revert::VmError; - #[macro_export] - macro_rules ! anvil_revert_generic_error { ($ ($ arg : tt) *) => { zksync_error :: error :: definitions :: Revert :: GenericError { message : format ! ($ ($ arg) *) } } ; } - pub use crate::anvil_revert_generic_error as generic_error; - } -} + pub mod halt { + pub use crate::error::definitions::Halt as HaltError; + pub use crate::error::definitions::Halt::ValidationFailed; + pub use crate::error::definitions::Halt::PaymasterValidationFailed; + pub use crate::error::definitions::Halt::PrePaymasterPreparationFailed; + pub use crate::error::definitions::Halt::PayForTxFailed; + pub use crate::error::definitions::Halt::FailedToMarkFactoryDependencies; + pub use crate::error::definitions::Halt::FailedToChargeFee; + pub use crate::error::definitions::Halt::FromIsNotAnAccount; + pub use crate::error::definitions::Halt::InnerTxError; + pub use crate::error::definitions::Halt::Unknown; + pub use crate::error::definitions::Halt::UnexpectedVMBehavior; + pub use crate::error::definitions::Halt::BootloaderOutOfGas; + pub use crate::error::definitions::Halt::ValidationOutOfGas; + pub use crate::error::definitions::Halt::TooBigGasLimit; + pub use crate::error::definitions::Halt::NotEnoughGasProvided; + pub use crate::error::definitions::Halt::MissingInvocationLimitReached; + pub use crate::error::definitions::Halt::FailedToSetL2Block; + pub use crate::error::definitions::Halt::FailedToAppendTransactionToL2Block; + pub use crate::error::definitions::Halt::VMPanic; + pub use crate::error::definitions::Halt::TracerCustom; + pub use crate::error::definitions::Halt::FailedToPublishCompressedBytecodes; + pub use crate::error::definitions::Halt::FailedBlockTimestampAssertion; + pub use crate::error::definitions::Halt::GenericError; + + #[macro_export] + macro_rules! anvil_halt_generic_error { + ($($arg:tt)*) => { + zksync_error::error::definitions::Halt::GenericError { message: format!($($arg)*) } + }; + } + pub use crate::anvil_halt_generic_error as generic_error; + } + pub mod revert { + pub use crate::error::definitions::Revert as RevertError; + pub use crate::error::definitions::Revert::General; + pub use crate::error::definitions::Revert::InnerTxError; + pub use crate::error::definitions::Revert::VmError; + pub use crate::error::definitions::Revert::Unknown; + pub use crate::error::definitions::Revert::GenericError; + + #[macro_export] + macro_rules! anvil_revert_generic_error { + ($($arg:tt)*) => { + zksync_error::error::definitions::Revert::GenericError { message: format!($($arg)*) } + }; + } + pub use crate::anvil_revert_generic_error as generic_error; + } + } pub mod compiler { - pub mod llvm_evm { - pub use crate::error::definitions::LLVM_EVM as LLVM_EVMError; - pub use crate::error::definitions::LLVM_EVM::GenericError; - #[macro_export] - macro_rules ! compiler_llvm_evm_generic_error { ($ ($ arg : tt) *) => { zksync_error :: error :: definitions :: LLVM_EVM :: GenericError { message : format ! ($ ($ arg) *) } } ; } - pub use crate::compiler_llvm_evm_generic_error as generic_error; - } - pub mod llvm_era { - pub use crate::error::definitions::LLVM_Era as LLVM_EraError; - pub use crate::error::definitions::LLVM_Era::GenericError; - #[macro_export] - macro_rules ! compiler_llvm_era_generic_error { ($ ($ arg : tt) *) => { zksync_error :: error :: definitions :: LLVM_Era :: GenericError { message : format ! ($ ($ arg) *) } } ; } - pub use crate::compiler_llvm_era_generic_error as generic_error; - } - pub mod solc { - pub use crate::error::definitions::Solc as SolcError; - pub use crate::error::definitions::Solc::GenericError; - #[macro_export] - macro_rules ! compiler_solc_generic_error { ($ ($ arg : tt) *) => { zksync_error :: error :: definitions :: Solc :: GenericError { message : format ! ($ ($ arg) *) } } ; } - pub use crate::compiler_solc_generic_error as generic_error; - } - pub mod solc_fork { - pub use crate::error::definitions::SolcFork as SolcForkError; - pub use crate::error::definitions::SolcFork::GenericError; - #[macro_export] - macro_rules ! compiler_solc_fork_generic_error { ($ ($ arg : tt) *) => { zksync_error :: error :: definitions :: SolcFork :: GenericError { message : format ! ($ ($ arg) *) } } ; } - pub use crate::compiler_solc_fork_generic_error as generic_error; - } - pub mod zksolc { - pub use crate::error::definitions::Zksolc as ZksolcError; - pub use crate::error::definitions::Zksolc::GenericError; - #[macro_export] - macro_rules ! compiler_zksolc_generic_error { ($ ($ arg : tt) *) => { zksync_error :: error :: definitions :: Zksolc :: GenericError { message : format ! ($ ($ arg) *) } } ; } - pub use crate::compiler_zksolc_generic_error as generic_error; - } - pub mod zkvyper { - pub use crate::error::definitions::Zkvyper as ZkvyperError; - pub use crate::error::definitions::Zkvyper::GenericError; - #[macro_export] - macro_rules ! compiler_zkvyper_generic_error { ($ ($ arg : tt) *) => { zksync_error :: error :: definitions :: Zkvyper :: GenericError { message : format ! ($ ($ arg) *) } } ; } - pub use crate::compiler_zkvyper_generic_error as generic_error; - } -} + pub mod llvm_evm { + pub use crate::error::definitions::LLVM_EVM as LLVM_EVMError; + pub use crate::error::definitions::LLVM_EVM::GenericError; + + #[macro_export] + macro_rules! compiler_llvm_evm_generic_error { + ($($arg:tt)*) => { + zksync_error::error::definitions::LLVM_EVM::GenericError { message: format!($($arg)*) } + }; + } + pub use crate::compiler_llvm_evm_generic_error as generic_error; + } + pub mod llvm_era { + pub use crate::error::definitions::LLVM_Era as LLVM_EraError; + pub use crate::error::definitions::LLVM_Era::GenericError; + + #[macro_export] + macro_rules! compiler_llvm_era_generic_error { + ($($arg:tt)*) => { + zksync_error::error::definitions::LLVM_Era::GenericError { message: format!($($arg)*) } + }; + } + pub use crate::compiler_llvm_era_generic_error as generic_error; + } + pub mod solc { + pub use crate::error::definitions::Solc as SolcError; + pub use crate::error::definitions::Solc::GenericError; + + #[macro_export] + macro_rules! compiler_solc_generic_error { + ($($arg:tt)*) => { + zksync_error::error::definitions::Solc::GenericError { message: format!($($arg)*) } + }; + } + pub use crate::compiler_solc_generic_error as generic_error; + } + pub mod solc_fork { + pub use crate::error::definitions::SolcFork as SolcForkError; + pub use crate::error::definitions::SolcFork::GenericError; + + #[macro_export] + macro_rules! compiler_solc_fork_generic_error { + ($($arg:tt)*) => { + zksync_error::error::definitions::SolcFork::GenericError { message: format!($($arg)*) } + }; + } + pub use crate::compiler_solc_fork_generic_error as generic_error; + } + pub mod zksolc { + pub use crate::error::definitions::Zksolc as ZksolcError; + pub use crate::error::definitions::Zksolc::GenericError; + + #[macro_export] + macro_rules! compiler_zksolc_generic_error { + ($($arg:tt)*) => { + zksync_error::error::definitions::Zksolc::GenericError { message: format!($($arg)*) } + }; + } + pub use crate::compiler_zksolc_generic_error as generic_error; + } + pub mod zkvyper { + pub use crate::error::definitions::Zkvyper as ZkvyperError; + pub use crate::error::definitions::Zkvyper::GenericError; + + #[macro_export] + macro_rules! compiler_zkvyper_generic_error { + ($($arg:tt)*) => { + zksync_error::error::definitions::Zkvyper::GenericError { message: format!($($arg)*) } + }; + } + pub use crate::compiler_zkvyper_generic_error as generic_error; + } + } pub mod core { - pub mod api { - pub use crate::error::definitions::API as APIError; - pub use crate::error::definitions::API::GenericError; - #[macro_export] - macro_rules ! core_api_generic_error { ($ ($ arg : tt) *) => { zksync_error :: error :: definitions :: API :: GenericError { message : format ! ($ ($ arg) *) } } ; } - pub use crate::core_api_generic_error as generic_error; - } - pub mod eravm { - pub use crate::error::definitions::EraVM as EraVMError; - pub use crate::error::definitions::EraVM::GenericError; - #[macro_export] - macro_rules ! core_eravm_generic_error { ($ ($ arg : tt) *) => { zksync_error :: error :: definitions :: EraVM :: GenericError { message : format ! ($ ($ arg) *) } } ; } - pub use crate::core_eravm_generic_error as generic_error; - } - pub mod exec { - pub use crate::error::definitions::ExecutionPlatform as ExecutionPlatformError; - pub use crate::error::definitions::ExecutionPlatform::GenericError; - #[macro_export] - macro_rules ! core_exec_generic_error { ($ ($ arg : tt) *) => { zksync_error :: error :: definitions :: ExecutionPlatform :: GenericError { message : format ! ($ ($ arg) *) } } ; } - pub use crate::core_exec_generic_error as generic_error; - } - pub mod seq { - pub use crate::error::definitions::Sequencer as SequencerError; - pub use crate::error::definitions::Sequencer::GenericError; - pub use crate::error::definitions::Sequencer::GenericSequencerError; - #[macro_export] - macro_rules ! core_seq_generic_error { ($ ($ arg : tt) *) => { zksync_error :: error :: definitions :: Sequencer :: GenericError { message : format ! ($ ($ arg) *) } } ; } - pub use crate::core_seq_generic_error as generic_error; - } -} + pub mod api { + pub use crate::error::definitions::API as APIError; + pub use crate::error::definitions::API::GenericError; + + #[macro_export] + macro_rules! core_api_generic_error { + ($($arg:tt)*) => { + zksync_error::error::definitions::API::GenericError { message: format!($($arg)*) } + }; + } + pub use crate::core_api_generic_error as generic_error; + } + pub mod eravm { + pub use crate::error::definitions::EraVM as EraVMError; + pub use crate::error::definitions::EraVM::GenericError; + + #[macro_export] + macro_rules! core_eravm_generic_error { + ($($arg:tt)*) => { + zksync_error::error::definitions::EraVM::GenericError { message: format!($($arg)*) } + }; + } + pub use crate::core_eravm_generic_error as generic_error; + } + pub mod exec { + pub use crate::error::definitions::ExecutionPlatform as ExecutionPlatformError; + pub use crate::error::definitions::ExecutionPlatform::GenericError; + + #[macro_export] + macro_rules! core_exec_generic_error { + ($($arg:tt)*) => { + zksync_error::error::definitions::ExecutionPlatform::GenericError { message: format!($($arg)*) } + }; + } + pub use crate::core_exec_generic_error as generic_error; + } + pub mod seq { + pub use crate::error::definitions::Sequencer as SequencerError; + pub use crate::error::definitions::Sequencer::GenericSequencerError; + pub use crate::error::definitions::Sequencer::GenericError; + + #[macro_export] + macro_rules! core_seq_generic_error { + ($($arg:tt)*) => { + zksync_error::error::definitions::Sequencer::GenericError { message: format!($($arg)*) } + }; + } + pub use crate::core_seq_generic_error as generic_error; + } + } pub mod foundry { - pub mod upstream { - pub use crate::error::definitions::FoundryUpstream as FoundryUpstreamError; - pub use crate::error::definitions::FoundryUpstream::GenericError; - #[macro_export] - macro_rules ! foundry_upstream_generic_error { ($ ($ arg : tt) *) => { zksync_error :: error :: definitions :: FoundryUpstream :: GenericError { message : format ! ($ ($ arg) *) } } ; } - pub use crate::foundry_upstream_generic_error as generic_error; - } - pub mod zksync { - pub use crate::error::definitions::FoundryZksync as FoundryZksyncError; - pub use crate::error::definitions::FoundryZksync::GenericError; - #[macro_export] - macro_rules ! foundry_zksync_generic_error { ($ ($ arg : tt) *) => { zksync_error :: error :: definitions :: FoundryZksync :: GenericError { message : format ! ($ ($ arg) *) } } ; } - pub use crate::foundry_zksync_generic_error as generic_error; - } -} + pub mod upstream { + pub use crate::error::definitions::FoundryUpstream as FoundryUpstreamError; + pub use crate::error::definitions::FoundryUpstream::GenericError; + + #[macro_export] + macro_rules! foundry_upstream_generic_error { + ($($arg:tt)*) => { + zksync_error::error::definitions::FoundryUpstream::GenericError { message: format!($($arg)*) } + }; + } + pub use crate::foundry_upstream_generic_error as generic_error; + } + pub mod zksync { + pub use crate::error::definitions::FoundryZksync as FoundryZksyncError; + pub use crate::error::definitions::FoundryZksync::GenericError; + + #[macro_export] + macro_rules! foundry_zksync_generic_error { + ($($arg:tt)*) => { + zksync_error::error::definitions::FoundryZksync::GenericError { message: format!($($arg)*) } + }; + } + pub use crate::foundry_zksync_generic_error as generic_error; + } + } pub mod hardhat { - pub mod upstream { - pub use crate::error::definitions::HardhatUpstream as HardhatUpstreamError; - pub use crate::error::definitions::HardhatUpstream::GenericError; - #[macro_export] - macro_rules ! hardhat_upstream_generic_error { ($ ($ arg : tt) *) => { zksync_error :: error :: definitions :: HardhatUpstream :: GenericError { message : format ! ($ ($ arg) *) } } ; } - pub use crate::hardhat_upstream_generic_error as generic_error; - } - pub mod zksync { - pub use crate::error::definitions::HardhatZksync as HardhatZksyncError; - pub use crate::error::definitions::HardhatZksync::GenericError; - #[macro_export] - macro_rules ! hardhat_zksync_generic_error { ($ ($ arg : tt) *) => { zksync_error :: error :: definitions :: HardhatZksync :: GenericError { message : format ! ($ ($ arg) *) } } ; } - pub use crate::hardhat_zksync_generic_error as generic_error; - } -} + pub mod upstream { + pub use crate::error::definitions::HardhatUpstream as HardhatUpstreamError; + pub use crate::error::definitions::HardhatUpstream::GenericError; + + #[macro_export] + macro_rules! hardhat_upstream_generic_error { + ($($arg:tt)*) => { + zksync_error::error::definitions::HardhatUpstream::GenericError { message: format!($($arg)*) } + }; + } + pub use crate::hardhat_upstream_generic_error as generic_error; + } + pub mod zksync { + pub use crate::error::definitions::HardhatZksync as HardhatZksyncError; + pub use crate::error::definitions::HardhatZksync::GenericError; + + #[macro_export] + macro_rules! hardhat_zksync_generic_error { + ($($arg:tt)*) => { + zksync_error::error::definitions::HardhatZksync::GenericError { message: format!($($arg)*) } + }; + } + pub use crate::hardhat_zksync_generic_error as generic_error; + } + } diff --git a/crates/zksync_error/src/packed.rs b/crates/zksync_error/src/packed.rs index 30dfa172..e3c0e939 100644 --- a/crates/zksync_error/src/packed.rs +++ b/crates/zksync_error/src/packed.rs @@ -1,22 +1,26 @@ + //! //! AUTOGENERATED BASED ON A SET OF JSON FILES, DO NOT EDIT MANUALLY //! +use std::fmt::Debug; + use crate::{ error::{ICustomError, IError, IUnifiedError}, identifier::Identifier, serialized::SerializedError, }; -use std::fmt::Debug; -#[derive(Clone, Debug, Eq, PartialEq, serde :: Deserialize, serde :: Serialize)] + +#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)] pub struct PackedError where U: Clone + Debug, { pub identifier: Identifier, pub message: String, - pub data: U, + pub data: U, // U = specific instance of ZksyncError } + impl IError for PackedError where T: Clone + Debug + serde::Serialize + for<'de> serde::Deserialize<'de>, @@ -24,13 +28,16 @@ where fn get_identifier(&self) -> Identifier { self.identifier.clone() } + fn get_message(&self) -> String { self.message.clone() } + fn get_data(&self) -> T { self.data.clone() } } + pub fn pack_unified(s: T) -> Result, serde_json::Error> where T: serde::Serialize + IUnifiedError + Clone + Debug, @@ -42,6 +49,7 @@ where data: s, }) } + pub fn pack(s: T) -> PackedError where T: serde::Serialize + ICustomError + Clone, @@ -50,6 +58,7 @@ where { pack_unified(s.to_unified()).expect("Serialization error") } + pub fn serialized(p: PackedError) -> SerializedError where T: Clone + Debug + serde::Serialize + IUnifiedError, @@ -74,6 +83,7 @@ where data, } } + impl std::fmt::Display for PackedError where T: Clone + Debug + serde::Serialize, @@ -86,7 +96,9 @@ where let data = value_pretty; f.write_fmt(format_args!( r#"{{ code: {code} ; message: "{message}"; data: {data} }}"#, + )) } } impl std::error::Error for PackedError where T: serde::Serialize + Debug + Clone {} + diff --git a/crates/zksync_error/src/serialized.rs b/crates/zksync_error/src/serialized.rs index 110426af..565add33 100644 --- a/crates/zksync_error/src/serialized.rs +++ b/crates/zksync_error/src/serialized.rs @@ -1,3 +1,4 @@ + //! //! AUTOGENERATED BASED ON A SET OF JSON FILES, DO NOT EDIT MANUALLY //! @@ -11,13 +12,16 @@ use crate::{ }; use std::error::Error; use std::fmt::Debug; + pub type ErrorCode = u32; -#[derive(Clone, Debug, Eq, PartialEq, serde :: Serialize, serde :: Deserialize)] + +#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)] pub struct SerializedError { pub code: ErrorCode, pub message: String, pub data: serde_json::Value, } + impl SerializedError { pub fn new_custom( kind: Kind, @@ -40,6 +44,7 @@ impl std::fmt::Display for SerializedError { )) } } + pub fn serialize(error: PackedError) -> Result where U: serde::Serialize + Clone + Debug, @@ -60,7 +65,9 @@ where data: serde_json::value::to_value(&error.data)?, }) } + pub fn unpack_untyped(se: &SerializedError) -> Result { + //FIXME unhandled errors let identifier = Identifier::decode(StructuredErrorCode::decode(se.code)).unwrap(); let skip_domain = se.data.as_object().unwrap().values().nth(0).unwrap(); let skip_subdomain = skip_domain.as_object().unwrap().values().nth(0).unwrap(); @@ -73,21 +80,29 @@ pub fn unpack_untyped(se: &SerializedError) -> Result(se: &SerializedError) -> Result where T: IUnifiedError + serde::Serialize + for<'de> serde::Deserialize<'de> + Clone, { serde_json::value::from_value(se.data.clone()) } + impl Error for SerializedError {} + impl IError for SerializedError { fn get_identifier(&self) -> Identifier { + //FIXME Identifier::decode(StructuredErrorCode::decode(self.code)).unwrap() } + fn get_message(&self) -> String { self.message.clone() } + fn get_data(&self) -> UntypedErrorObject { + //FIXME unpack_untyped(self).expect("Internal error") } } + diff --git a/crates/zksync_error/src/untyped.rs b/crates/zksync_error/src/untyped.rs index e3bbcb04..0bc0c417 100644 --- a/crates/zksync_error/src/untyped.rs +++ b/crates/zksync_error/src/untyped.rs @@ -1,12 +1,15 @@ + //! //! AUTOGENERATED BASED ON A SET OF JSON FILES, DO NOT EDIT MANUALLY //! use crate::identifier::Identifier; -#[derive(Debug, Clone, PartialEq, Eq, serde :: Serialize, serde :: Deserialize)] + +#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] pub struct UntypedErrorObject { pub identifier: Identifier, pub name: String, - pub fields: serde_json::Map, - pub raw: serde_json::Value, + pub fields: serde_json::Map, // Specific value introduced by user; unpacked from the Domain/subdomain and error name + pub raw: serde_json::Value, // Specific value introduced by user; unpacked from the Domain/subdomain. } +