codegen: Add codegen error (#841)

* codegen: Add codegen error

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Use codegen error instead of aborts

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Remove `proc-macro-error` dependency

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* macro/subxt: Transform codegen error into compile_error!

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Pretty printing for `CodegenError`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update cargo.lock

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* tests: Adjust testing for codegen error

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Fix documentation example

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Export `CodegenError`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Use collect::<Result<_>, _>()

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Adjust comment regarding error printing

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Improve error messages

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2023-03-03 19:57:46 +02:00
committed by GitHub
parent 5320ca9d55
commit a7b45ef1d1
18 changed files with 405 additions and 322 deletions
+6 -4
View File
@@ -180,7 +180,7 @@ pub fn subxt(args: TokenStream, input: TokenStream) -> TokenStream {
}
let mut type_substitutes = TypeSubstitutes::new(&crate_path);
type_substitutes.extend(args.substitute_type.into_iter().map(
if let Err(err) = type_substitutes.extend(args.substitute_type.into_iter().map(
|SubstituteType { ty, with }| {
(
ty,
@@ -190,7 +190,9 @@ pub fn subxt(args: TokenStream, input: TokenStream) -> TokenStream {
}),
)
},
));
)) {
return err.into_compile_error().into()
}
let should_gen_docs = args.generate_docs.is_present();
match (args.runtime_metadata_path, args.runtime_metadata_url) {
@@ -206,7 +208,7 @@ pub fn subxt(args: TokenStream, input: TokenStream) -> TokenStream {
crate_path,
should_gen_docs,
)
.into()
.map_or_else(|err| err.into_compile_error().into(), Into::into)
}
(None, Some(url_string)) => {
let url = Uri::from_str(&url_string).unwrap_or_else(|_| {
@@ -220,7 +222,7 @@ pub fn subxt(args: TokenStream, input: TokenStream) -> TokenStream {
crate_path,
should_gen_docs,
)
.into()
.map_or_else(|err| err.into_compile_error().into(), Into::into)
}
(None, None) => {
abort_call_site!("One of 'runtime_metadata_path' or 'runtime_metadata_url' must be provided")