Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve input body when attribute macro expansion fails (#1244) #1245

Merged
merged 6 commits into from
Jan 30, 2024

Conversation

tyranron
Copy link
Member

@tyranron tyranron commented Jan 30, 2024

Resolves #1244

Synopsis

See #1244 (comment):

Describe the bug

#[graphql_object] attribute macro prevents syntax errors from being shown:

"#[graphql_object] attribute is applicable to non-trait `impl` blocks only",

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:

if let Ok(mut ast) = syn::parse2::<syn::ItemImpl>(body) {

Solution

Preserve input body when proc_macro_attribute expansion fails.

Checklist

  • Tests are added
  • CHANGELOG entry is added
  • Documentation is updated (not required)

@tyranron tyranron added enhancement Improvement of existing features or bugfix k::api Related to API (application interface) area::codegen Related to codegen functionality labels Jan 30, 2024
@tyranron tyranron added this to the 0.16.0 milestone Jan 30, 2024
@tyranron tyranron self-assigned this Jan 30, 2024
@tyranron tyranron marked this pull request as ready for review January 30, 2024 14:49
@tyranron tyranron merged commit f363b0d into master Jan 30, 2024
173 checks passed
@tyranron tyranron deleted the 1244-fix-incorrect-syntax-expansion branch January 30, 2024 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area::codegen Related to codegen functionality enhancement Improvement of existing features or bugfix k::api Related to API (application interface)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

#[graphql_object] hides syntax errors
1 participant