mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 05:07:55 +00:00
Improve error handling in proc-macros, handle DispatchError etc. (#123)
* Improve error handling. * Fix build. * Handle runtime errors. * Add runtime trait for better type inference. * Use runtime trait part 1. * wip * Add support for sudo. * Finish error handling. * Fix tests. * Fix clippy warnings.
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
use crate::utils;
|
||||
use heck::SnakeCase;
|
||||
use proc_macro2::TokenStream;
|
||||
use proc_macro_error::abort;
|
||||
use quote::{
|
||||
format_ident,
|
||||
quote,
|
||||
@@ -48,8 +49,10 @@ type ModuleAttrs = utils::Attrs<ModuleAttr>;
|
||||
fn ignore(attrs: &[syn::Attribute]) -> bool {
|
||||
for attr in attrs {
|
||||
if let Some(ident) = attr.path.get_ident() {
|
||||
if ident.to_string() == "module" {
|
||||
let attrs: ModuleAttrs = syn::parse2(attr.tokens.clone()).unwrap();
|
||||
if ident == "module" {
|
||||
let attrs: ModuleAttrs = syn::parse2(attr.tokens.clone())
|
||||
.map_err(|err| abort!("{}", err))
|
||||
.unwrap();
|
||||
if !attrs.attrs.is_empty() {
|
||||
return true
|
||||
}
|
||||
@@ -69,10 +72,12 @@ fn with_module_ident(module: &syn::Ident) -> syn::Ident {
|
||||
|
||||
pub fn module(_args: TokenStream, tokens: TokenStream) -> TokenStream {
|
||||
let input: Result<syn::ItemTrait, _> = syn::parse2(tokens.clone());
|
||||
if input.is_err() {
|
||||
let input = if let Ok(input) = input {
|
||||
input
|
||||
} else {
|
||||
// handle #[module(ignore)] by just returning the tokens
|
||||
return tokens
|
||||
}
|
||||
let input = input.unwrap();
|
||||
};
|
||||
|
||||
let subxt = utils::use_crate("substrate-subxt");
|
||||
let module = &input.ident;
|
||||
|
||||
Reference in New Issue
Block a user