Closed tyranron closed 9 months ago
Resolves #1244
See https://github.com/graphql-rust/juniper/issues/1244#issue-2105985314:
Describe the bug #[graphql_object] attribute macro prevents syntax errors from being shown: https://github.com/graphql-rust/juniper/blob/8a69e14c8bbbbd1da8bdefe3e30c60ff342ed863/juniper_codegen/src/graphql_object/attr.rs#L35 To Reproduce Steps to reproduce the behavior: 1. Add a valid `struct`; 2. Impl fields resolvers with `#[graphql_object]`; 3. Broke syntax inside method impl. struct MyObject { my_field: i32, } #[graphql_object] // ERROR: #[graphql_object] attribute is applicable to non-trait `impl` blocks only impl MyObject { fn my_field(&self) -> i32 { self.self.my_field // actual syntax error is not reported. } } Expected behavior A syntax error will be shown. Additional context The problem is happening because attribute macro ignores errors of impl block parsing: https://github.com/graphql-rust/juniper/blob/8a69e14c8bbbbd1da8bdefe3e30c60ff342ed863/juniper_codegen/src/graphql_object/attr.rs#L22
Describe the bug
#[graphql_object] attribute macro prevents syntax errors from being shown:
#[graphql_object]
https://github.com/graphql-rust/juniper/blob/8a69e14c8bbbbd1da8bdefe3e30c60ff342ed863/juniper_codegen/src/graphql_object/attr.rs#L35
To Reproduce Steps to reproduce the behavior:
1. Add a valid `struct`; 2. Impl fields resolvers with `#[graphql_object]`; 3. Broke syntax inside method impl.
struct MyObject { my_field: i32, } #[graphql_object] // ERROR: #[graphql_object] attribute is applicable to non-trait `impl` blocks only impl MyObject { fn my_field(&self) -> i32 { self.self.my_field // actual syntax error is not reported. } }
Expected behavior
A syntax error will be shown.
Additional context
The problem is happening because attribute macro ignores errors of impl block parsing:
impl
https://github.com/graphql-rust/juniper/blob/8a69e14c8bbbbd1da8bdefe3e30c60ff342ed863/juniper_codegen/src/graphql_object/attr.rs#L22
Preserve input body when proc_macro_attribute expansion fails.
body
proc_macro_attribute
Resolves #1244
Synopsis
See https://github.com/graphql-rust/juniper/issues/1244#issue-2105985314:
Solution
Preserve input
body
whenproc_macro_attribute
expansion fails.Checklist
Documentation is updated(not required)